[erlang-questions] -define
Richard O'Keefe
ok@REDACTED
Thu Feb 18 23:56:16 CET 2010
On Feb 18, 2010, at 11:49 PM, Robert Virding wrote:
> There is a simple reason for this: sheer laziness by the original
> writer of the epp module, me. Now I suppose it is difficult to change
> because of backwards compatibility. The problem is compounded byt the
> feature that macro expansions don't have to be complete erlang
> expressions so sometimes you can't tell the macro definition is over
> until you hit the '.' .
>
The problem is that if
-define(foo, bar.
defines {{?foo}} to mean {{bar}}
and
-define(foo, bar].
defines {{?foo}} to mean {{bar]}}
we'd expect that
-define(foo, bar).
would define {{?foo}} to mean {{bar)}}.
But it doesn't. The problem here is inconsistency: the right
hand of a -define is everything to the dot except when it isn't.
As it happens, in the 1.5 million lines of Erlang code that I
examined, there were about 3 occurrences of -define without a
closing ); it was trivial to add a ) without breaking anything;
and with those exceptions they were all bracket balanced.
The on-line reference manual, section 7.2,
http://www.erlang.org/doc/reference_manual/macros.html#id2274714
says
"A macro is defined the following way:
-define(Const, Replacement).
-define(Func(Var1,...,VarN), Replacement)."
and there's no hint that the final ) is optional. So I don't
think it _would_ be difficult to enforce this. A good step would
be to have a warning message from the preprocessor when a -define
has no right parenthesis before the closing dot.
>
More information about the erlang-questions
mailing list