New EEP draft: Pinning operator ^ in patterns

Raimo Niskanen raimo+erlang-questions@REDACTED
Wed Jan 20 17:27:16 CET 2021


On Wed, Jan 20, 2021 at 04:22:26PM +0100, Kostis Sagonas wrote:
> On 1/20/21 3:42 PM, Raimo Niskanen wrote:
> > 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?
> 
> Raimo: Your question about nested funs is a good one.
> 
> However, I thought that ^ was meant to be used in *patterns* (this is
> even in the subject of this sad thread), and I do not see ^ being used
> in patterns in your example.
> 
> Am I missing anything?

Nope.  I missed that.  Felt like something one might want to do.

Let's see if I manage to use patterns instead:

1: foo(Y) ->
2:      F = fun (Y) ->
3:           FF = fun (Y) ->
4:                    ^Y = Y - 1
5:                end,
6:           FF(Y + 1)
7:          end,
8:      F(Y + 1).

I guess that would produce warnings for shadowing on line 2 and 3.
I guess that ^Y on line 4 refers to the Y bound on line 2.
I guess that warn_unpinned_vars would not produce any warnings.
Can I match against the Y bound on line 1 from within FF/1?

> 
> Are you still of the opinion that this, supposedly "pinning operator"
> (which is neither "pinning" anything nor an "operator") makes Erlang
> less confusing a language?

That is what I am trying to find out...

Cheers
/ Raimo

> 
> Cheers,
> Kostis
> 
> 
> 
> 
> 
> 
> 
> 
> När du har kontakt med oss på Uppsala universitet med e-post så innebär det att vi behandlar dina personuppgifter. För att läsa mer om hur vi gör det kan du läsa här: http://www.uu.se/om-uu/dataskydd-personuppgifter/
> 
> E-mailing Uppsala University means that we will process your personal data. For more information on how this is performed, please read here: http://www.uu.se/en/about-uu/data-protection-policy

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


More information about the erlang-questions mailing list