New EEP draft: Pinning operator ^ in patterns
Tue Jan 19 13:51:08 CET 2021
Calling it "pinning" is what Elixir does. They use the same symbol and the
same semantics. Borrowing the semantics, it would be a bad idea to cause
confusion by inventing new terminology or use a different symbol (luckily,
^ happened to be completely free for use in Erlang as well), regardless of
whether I thought I could come up with some better term, especially since
people often jump between Erlang and Elixir projects these days. The
reading should be straightforward: the interpretation of the variable is
"pinned" to the existing scope, regardless of how unmarked variables are
being interpreted in that particular pattern.
Also, Elixir documentation calls ^ an operator. It's not an operator on the
expression level, but I've often seen things like namespace selectors such
as '.' and '::' be referred to as operators. Call it a colloquialism if you
will. It could probably be regarded as an operator on a meta-level, though,
since it marks a phrase for being interpreted in a particular environment.
For instance, LISP backquotes are often referred to as operators.
Haskell, OCaml, etc., don't have this feature, but it could simply be
because nobody thought about trying it. We should consider the possibility
that Elixir invented something new and useful.
I would also (I think) like a rule that simply treats all variables as new
in all patterns - but I would have to make more large scale experiments to
see how well it would work in practice. This we can however not do - yet -
without breaking existing code. But introducing ^-annotation both addresses
immediate problems of readability and maintainability as well as make the
way clear for such a future change.
Den sön 17 jan. 2021 kl 13:45 skrev Richard O'Keefe <raoknz@REDACTED>:
> Am I the only one who finds the word "pinning"
> confusing? I know what "pinning a bone" means.
> I know what "pinning an insect to a board"
> means. I know what "pinning an enemy/opponent"
> means in war, wrestling, or chess. I am not an
> Elixir programmer (the syntax has always struck
> me as, um, more pain than whatever other gain I
> might get from Elixir), so I don't know what
> "to pin" means in Elixir.
> I am also confused by it being called an operator.
> It appears to be an ANNOTATION, not an operator,
> some sort of "hey I really meant to have an
> already bound variable here" annotation. It
> certainly doesn't *act* like an operator.
> If it were an operator, I'd be asking what ^X+1
> meant and what ^1+X meant.
> Since Erlang has two notions of equality, I
> would be much happier with an optional style
> rule that says "all variables in a pattern
> must be new" (like patterns in Haskell, SML,
> and so on) forcing you to show in the guard
> which version of equality you wanted. This
> would be a pure restriction on existing
> Erlang syntax; any code accepted under this
> rule would also be acceptable under unrestricted
> Erlang and would have the same meaning.
> I note that none of the other functional
> languages I use (Haskell, SML, OCaml, F#)
> have any analogue of ^X and they don't need
> On Sun, 17 Jan 2021 at 21:18, Valentin Micic <v@REDACTED> wrote:
>> > On 15 Jan 2021, at 17:35, Raimo Niskanen <
>> raimo+erlang-questions@REDACTED> wrote:
>> > 1) Would the language be a better language with a mandatory pinning
>> I think this must always be our starting point.
>> Without asking this question, we might wake up one day programming in C++
>> (not that anything is wrong with that… well, other than esoteric syntax).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions