Syntax of fun expressions
Kostis Sagonas
kostis@REDACTED
Sat Mar 6 10:25:37 CET 2010
In most languages, one is typically allowed to use parentheses in most
places.
Indeed, in Erlang one can write all these below:
1> lists:last([1,2,3]).
3
2> lists:last(([1,2,3])).
3
3> lists:(last)([1,2,3]).
3
4> (lists):last([1,2,3]).
3
5> (lists):(last)(([1,2,3])).
3
The same is not allowed in the constituents of fun expressions.
One is not allowed to put parentheses in any component of:
fun M:F/A
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, [])
to
spawn_link(fun (?MODULE):rec/0)
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.
Kostis
More information about the erlang-bugs
mailing list