[erlang-questions] -define
Kostis Sagonas
kostis@REDACTED
Thu Feb 18 16:14:22 CET 2010
Richard O'Keefe wrote:
> I've been trying out a weak pretty-printer for Erlang.
> (By "weak" I mean that it takes care of indentation but
> does not do anything about line breaking.) It's supposed
> to be something I can build into my text editor.
>
> When I tried feeding other people's Erlang code into it,
> I ran into some problems.
>
> I was aware that when you write
>
> -define(LHS, RHS).
>
> the stuff in RHS did not have to be bracket balanced, so
> that
> -define(LP, ().
> -define(RP, )).
>
> are OK.
> What I was *not* aware of was that there doesn't even have
> to be a closing right parenthesis at all.
>
> -module(ick).
> -export([ick/0]).
> -define(ICK, {1}.
>
> ick() -> ?ICK.
>
> The Erlang compiler is perfectly happy with this.
> There are several occurrences of this in the Erlang/OTP sources,
> but there doesn't seem to be any reason why.
I want to add my support to Richard's mail (and share his justified
frustration) about the Erlang preprocessor. It should really be fixed
so that it does not break the principle of least astonishment from what
people (perhaps naively) expect from using other preprocessors like C's.
The situation is currently very problematic for any sort of tool that
wants to process Erlang source code. For example, tidier (*) that uses
the epp_dodger module of the syntax_tools application, has trouble in
some -defines which are considered OK by epp but not by epp_dodger. The
most common one is those that have commas in what Richard calls their
RHS, as in:
-define(test(X), X =/= 42, X =/= 54, X =/= 666).
I really do not like this -- and epp_dodger seems to agree with me.
Allowing the above to be written even without the right parenthesis is
even more problematic.
I do not buy Robert's comments about "this being difficult to change
because of backwards compatibility", as I have trouble imagining a
-define that _really_ needs to be without a right parenthesis. Even if
some existing code does not compile anymore, the fix is just adding a
right parenthesis that should have been there in the first place!
We should not stop being afraid of doing such changes as they are clear
improvements both for the language, the various tools for it, and for
the community in general.
At least judging from Ulf's mail, there is a very simple fix to this
problem, and I urge the OTP team to try this proposed change and include
it in R14. Perhaps Richard can help by sending a list of -defines in
Erlang/OTP that are without right parentheses to at least see if there
is some legitimate reason for them to be without.
Kostis
(*) http://tidier.softlab.ntua.gr/
More information about the erlang-questions
mailing list