[erlang-questions] Re: Multi-line comments in Erlang

Richard O'Keefe ok@REDACTED
Tue Dec 14 01:10:33 CET 2010


On 13/12/2010, at 10:40 PM, Zvi wrote:
> The reason I posted this is because I found out, that Matlab/Octave
> supports this style of comment (%{ ... %}), even that it's IDE has
> perfect support for commenting and uncommenting entire sections of
> source files with end of line comments (... % COMMENT).
> Now Matlab is not the best example of programming language, but I
> think in this particular feature they did it right.

Interestingly, they did it DIFFERENTLY from Modula-2, Lisp, Haskell,
SML, and other languages I know that have nesting comments.
From the MatLab manual:

Block Comments.

To write comments that require more than one line, use the block comment operators, %{ and %}:

%{
This next block of code checks the number of inputs 
passed in, makes sure that each input is a valid data 
type, and then branches to start processing the data.
%}

Note

The %{ and %} operators must appear alone on the lines that immediately precede and follow
the block of help text.  Do not include any other text on these lines.

White space is apparently allowed, but
	x = x {% +1 %};
is not legal, and as for
	{%
	s = '%}';
	%}
well, the manual does not make it clear whether this is an error (because there is
other text on the first %} line, or whether the first '%}' line simply is not recognised
as an end-of-comment line.

This is an interesting variation, but it means that these comments are useless
for commenting out subexpressions.

Of course, like every other nesting comment proposal I've ever seen,
this one IS still broken.

Theorem: There exists a valid block of MatLab code such that
adding a '%{' line at the beginning and a '%}' line at the end
does not result in a valid block comment.  Further, there exists
such a block that contains no string literals or line continuations.
Proof:
	x = 1;
	%}
	y = 2;
The second line here is a valid end-of-line comment.

As Zvi says, the MatLab IDE *will* comment/uncomment blocks correctly using
end-of-line comments.




More information about the erlang-questions mailing list