New EEP draft: Pinning operator ^ in patterns

Richard Carlsson carlsson.richard@REDACTED
Wed Jan 20 20:39:03 CET 2021

Den ons 20 jan. 2021 kl 15:42 skrev Raimo Niskanen <

> I have vague feeling that this has been asked,
> but since I can not find it:
> How is nested fun()s handled?
> foo(Y) ->
>     F = fun (X) ->
>             Y = X + ^Y,
>             FF = fun (Z) ->
>                      Z + ^Y
>                  end,
>             FF(Y)
>         end,
>     F(Y).
> Does the innermost Z + ^Y access the outermost Y from foo(Y), or the Y
> bound in F/1 i.e Y = X + ^Y?
> Is there a way to choose which of the outer Y:s to refer to from within
> FF/1?

No, the ^X notation is only allowed in patterns, it is an error to use it
elsewhere. It is only needed in patterns since they form the boundary
between existing bindings and new bindings. While I could imagine ways to
interpret ^X technically in expressions as well, like some kind of de
Bruijn notation, I think such uses would lead to madness.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the erlang-questions mailing list