Re: New EEP draft: Pinning operator ^ in patterns
Richard Carlsson <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CANKG3zmCr0n9XUEvVkt2Yyci8AxxYNpnsEzyoAocnmr22b4GPQ@mail.gmail.com> |
Den tis 19 jan. 2021 kl 14:25 skrev Fernando Benavides < [email protected]>: > Oh! I didn't understand that correctly. > In that case, what would be the meaning of [X, ^X] = something()? Will > that even be a valid expression? > > I'm assuming that f(X, X) ->... Will indeed need to be written as f(X, ^X) > ->..., right? > ^X always means a single thing - "the value of X in the surrounding scope". Any unmarked X has the same meaning as today. In a simple match expression [X, ^X] = something(), or a case clause "case something() of [X, ^X] -> ..." you'd get a warning about the unmarked X (if you enable the warnings), but it keeps it's existing meaning, which is the same as ^X for these kinds of patterns. In a fun head or list comprehension generator pattern, you'd get the usual warning that the unmarked X is shadowing (assuming it has a binding). If you do mark a variable as ^X, and it *doesn't* have a previous binding, that's a normal "unbound variable" error, just as if you had written "X1 when X =:= X1 -> ..." and X doesn't actually exist. This means that the clause doesn't accidentally start to match on any value in case you rename X to something else above. /Richard