66
6
COBOL is a very old language, at the time of writing it is 58 years old. It is so old, in fact, that it has a very interesting quirk: the first six characters of each line are comments.
Why is this, you ask? Well, those 6 characters were intended to be used as line numbers, back in the day where programs weren't completely digital and typed out on a computer.
In addition, the seventh character could only be part of a very small set (it is usually *
to comment out the line or a space to separate the line number from the code)
But what if you're on a more digital system, and you just want the raw program?
The comment system
There are two types of comments in COBOL: line comments and the aforementioned "line number" comments.
Uncommenting line numbers is simple: just take the first seven (six plus a single space) characters off each line.
000000 apple
000001 banana
celery donuts
would become:
apple
banana
donuts
Line comments make it a bit more difficult.
A line comment is started with an asterisk *
placed in the seventh character position on the line, like so:
000323* this is a comment
This is not a line comment:
*00000 this isn't a comment
To uncomment a line comment, just remove the whole line.
An example commented "program":
000000 blah blah
000001* apples
000002 oranges?
000003* yeah, oranges.
000*04 love me some oranges
The uncommented version:
blah blah
oranges?
love me some oranges
In other words, to uncomment a string, remove the first six characters of each line, then return all but the first character of every line that does not begin with a star.
The challenge
Create a program or function that takes a commented program and returns its uncommented variant.
Clarifications
- Asterisks (
*
) will never be found anywhere outside the first seven characters on a line (we're not asking you to verify syntax) - Each line will always have at least 7 characters.
- You may assume the seventh character is always an asterisk or a space.
- Input or output may be a matrix or list.
- Only printable ASCII characters (plus newline) must be handled.
- You may output with a trailing newline. You may also assume that the input will have a trailing newline, if you so choose.
Scoring
Since this is code-golf, the answer with the least bytes wins!
DISCLAIMER: I do not actually know COBOL and do not claim to. If any of the claims about COBOL I have made in this question are incorrect, I take no responsibility.
23Line numbers are not comments. They are a column. Terminology please. – user207421 – 2017-08-24T05:47:38.890
2Your examples all have a space after the
*
. Is this a coincidence? – Neil – 2017-08-24T10:13:00.3731@Neil Yes, it is. The eighth character can be anything. – LyricLy – 2017-08-24T10:17:29.793
6Old does not automatically imply bad. I have worked in an Agile COBOL shop. They could do things on the AS/400 we could not do in Java. – Thorbjørn Ravn Andersen – 2017-08-24T12:06:42.370
1Heh... I actually wrote a COBOL CopyBook parser that only works if the fields aren't packed. Just transforms it into JSON
key:{key:{key:length,key:length}}
. Strips all formatting data and typing data though. – Magic Octopus Urn – 2017-08-24T14:50:56.2504Can there be a space in the first 6 characters? – None – 2017-08-24T15:30:54.410
Are you assuming no wholly blank lines (just carriage returns)? I feel like that is something that'd be legal and important, but would force people to do a few more null-checks. – Southpaw Hare – 2017-08-24T17:24:03.423
Can you assume that at least one line is not a line comment? – betaveros – 2017-08-24T18:49:29.880
@stanri Yes, there can be. – LyricLy – 2017-08-24T20:20:00.677
@SouthpawHare An empty line would violate the rule that there will always be at least 7 characters in a line. Empty lines do not have to be handled. – LyricLy – 2017-08-24T20:21:24.853
@betaveros You cannot. – LyricLy – 2017-08-24T20:21:51.917
Would it be OK to have the input as an array where the last entry is something like
NULL
, to indicate end of input? e.g.char** program = { "000000 hello", "000001 world", NULL };
– simon – 2017-08-24T21:36:01.010@gurka Sure, that's OK. – LyricLy – 2017-08-24T21:38:24.400
@EJP So true. Those of us who actually used punched cards had a strange fondness for our COBOL compilers which strictly enforced the ascending line numbers. – ClickRick – 2017-08-26T09:56:29.897
Is the line number significant, since it defines the order of program lines in COBOL? – Kwebble – 2017-08-26T21:51:14.143
@Kwebble It is not significant. – LyricLy – 2017-08-26T22:14:40.017
1Column 7 in addition to a space, could also contain not only * (asterix) a comment but also - (hyphen) indicating a continuation line and / (forward slash) form feed – Rolf of Saxony – 2017-08-27T06:31:35.000
@ClickRick Sure. I built one. Well it was an option. – user207421 – 2017-08-27T06:51:18.640
Hi Folks! Sorry, I know this is an off-topic comment (feel free to flag it as such)... Does anyone know what happened to the Code Golf sandbox? Is there one, still? – AJFaraday – 2019-09-25T13:22:29.817