[erlang-questions] Multi-line comments in Erlang
Richard O'Keefe
ok@REDACTED
Wed Dec 8 01:06:11 CET 2010
On 8/12/2010, at 12:41 PM, Jesper Louis Andersen wrote:
> On Tue, Dec 7, 2010 at 11:14 PM, Richard O'Keefe <ok@REDACTED> wrote:
>>
>> /* ... */ comments have no known advantages over % comments;
>> with adequate editing tools it is equally easy to "comment out"
>> or "comment in" a region either way and they are equally easy
>> to type or reformat.
>
> Is it, in Prolog acceptable to nest layers of /* .. */ ?
No, most definitely NOT. I did say they were PL/I-style comments,
which do not nest. Nesting comments are one of those clever ideas
that turn out to be really dumb, because they don't actually work.
> It tend to be
> that case which is hard to implement.
As it happens, my Prolog tidier has code to convert plain bracketed
comments to standard form *and* nesting bracketed comments to
standard form. As you can see, there is not a great deal of
difference.
static void
com2plain(FILE * card, FILE *line, int astcom, int endcom) {
int c;
int state;
enter_comment
for (state = 1; (c = getc(card)) >= 0; ) {
if (c == endcom && state != 0) break;
state = c == astcom;
copy_comment(c);
}
leave_ast_comment
if (c < 0) SyntaxError(eofinrem);
}
static void
com2nest(FILE * card, FILE *line, int begcom, int astcom, int endcom) {
int c;
int state;
int level;
enter_comment
for (state = 1, level = 1; (c = getc(card)) >= 0; ) {
if (c == endcom && state == 1) {
if (--level == 0) break;
} else
if (c == astcom && state == 2) {
level++;
}
state = c == astcom ? 1 : c == begcom ? 2 : 0;
copy_comment(c);
}
leave_ast_comment
if (c < 0) SyntaxError(eofinrem);
}
Today I'd do that a bit differently, of course.
> Today, I see little need for them.
More information about the erlang-questions
mailing list