Syntax of fun expressions
Sat Mar 6 10:25:37 CET 2010
In most languages, one is typically allowed to use parentheses in most
Indeed, in Erlang one can write all these below:
The same is not allowed in the constituents of fun expressions.
One is not allowed to put parentheses in any component of:
For example, fun (lists):last/1 results in a syntax error.
I think this is inconsistent.
Why do I want to add parentheses around fun constituents you may ask?
A tidier user complained that tidier's suggestion to transform
spawn_link(?MODULE, rec, )
resulted in a syntax error. Arguably, (?MODULE) expresses the grouping
of ? with MODULE in ?MODULE:rec/0 better than without parentheses.
Moreover, apparently the parser insists that M and F are *statically*
atoms (and A integer) so one cannot write:
M = lists,
F = fun M:last/1
I can possibly understand why A has to be statically known, but why
should M and F also be? I thought, perhaps wrongly, that the sequence
above is anyway transformed to its equivalent one:
M = lists,
F = fun (_L) -> M:last(_L) end.
More information about the erlang-bugs