Hello.
I’m relatively new to Elixir, but not to programming generally.
In the learning process I’ve been recently struck with following inconsistency, at “capturing” an anonymous function with &
operator:
iex> &(:just_return_this_atom)
** (CompileError) iex:350: invalid args for &, expected an expression in the format of &Mod.fun/arity, &local/arity or a capture containing at least one argument as &1, got: :just_return_this_atom
I’ve read the docs, where the limitation is stated:
The only restrictions when creating anonymous functions is that at least one placeholder must be present, i.e. it must contain at least
&1
, and that block expressions are not supported:
What is the rationale behind this limitation ? I’ve already searched some mailing lists but so far no satisfactory explanation has been found.
I’m aware by choosing unary ampersand operator for converting both - normal expression and function name with arity - to Function instance, already did introduced ambiguity itself. In addition, by choosing slash operator both - for arithmetic division and separator between function name and its arity, only made it worse.
As far as I know, function_name/arity_num
is not even valid token itself and does exist only for the sole purpose of capturing with &
. Just in this single special case.
Are there some plans, work in core dev to fix above described inconsistency in some major release, like 2.0 ? Or find it as unsolvable problem without breaking backward compatibility and accepting damage has been already done ?
I’d probably need dive deeper into Elixir’s parser, but so far I’d imagine it could be handled with fixing operators precedence incl. parens and capturing function_name/arity_num
would always require explicit enclosing in parens.