nested captures via & are not allowed

57 views
Skip to first unread message

ivan.y...@gmail.com

unread,
Sep 11, 2020, 8:45:21 AM9/11/20
to elixir-lang-core
I just ran into this error "nested captures via & are not allowed" having no nested captures whatsoever,, but using captures in a chain of operations with custom operator, like this:
`value ~> &op/1 ~> &op2/1` where ~> is basically an alias for some function, so when rewritten it looks like this: `flat_map(flat_map(value, &op/1), &op2/1)` and it works totally fine. Is there a reason why this shouldn't be allowed or the compiler is wrong on detecting a nesting here?

José Valim

unread,
Sep 11, 2020, 8:48:42 AM9/11/20
to elixir-l...@googlegroups.com
The & has low precedence (low binding). Therefore, "value ~> &op/1 ~> &op2/1" is being parsed as "value ~> &(op/1 ~> &op2/1)", which is where the warning comes from.

Proof:

iex(1)> Macro.to_string(quote do: value ~> &op/1 ~> &op2/1)
"value ~> &(op / 1 ~> &op2/1)"

ivan.y...@gmail.com

unread,
Sep 11, 2020, 8:54:58 AM9/11/20
to elixir-lang-core

Ah, thanks, parentheses indeed fix that.
Reply all
Reply to author
Forward
0 new messages