New EEP draft: Pinning operator ^ in patterns

Richard Carlsson carlsson.richard@REDACTED
Tue Jan 19 16:06:26 CET 2021

Den tors 14 jan. 2021 kl 19:14 skrev Leonard B <leonard.boyce@REDACTED

> I ask myself, since there are already 'erlangy' scoping rules for
> variables (esp with funs) would it not just be better to change those
> to more fully allow defined variables from outer scope within
> fun/comprehension scope?
> IE, if a variable is previously assigned within the outer scope use
> that variable within the inner scope.
> This, in my addled mind, makes more sense
> EG:
> %% X is from outer scope, L is from outer scope, V is local to
> comprehension
> X = 5.
> L = [1,2,3,4,5].
> [V || {X, V} <- L].
It's certainly doable, especially since we already have warnings by default
against shadowing. We'd need to first start deprecating, then forbidding
shadowing, and then finally start allowing use of already bound variables
instead. However it does nothing about the current situation with ordinary
patterns in cases, receives, etc., making the language more uniform but
adding even more places where it can be hard to see what is going on, or to
accidentally change the meaning of a clause by renaming a variable.

By adding the ^-annotations, we get both worlds: complete clarity about
what a variable use means, as well as the ability to refer to already bound
ones in funs and list comprehensions, while keeping the possibility of
using shadowing for fun variables (something many would see as a
fundamental property of lambda expressions).


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

More information about the erlang-questions mailing list