in reply to Exegesis 6 - Named binding

There is something I dont understand in the new Exegesis, namely (page 7 bottom):
# Named binding... ($who, $why) := (why => $because, who => "me"); # same as: $who := "me"; $why := $because;
This makes no sence to me. Simply because a pair has the same key value as one of the variables on the left side, it is assigned to that?
Not assigned, bound. Binding in perl 6 does the same thing as the aliasing of foreach's loop variable, only you can do it everywhere. Once you execute this statement, $why and $because are essentially the same variable--they both point to the same underlying structure. $who is bound to the constant "me", which means printing $who prints "me" and trying to assign to it throws an error because you're trying to assign to a constant.

Perl 6 is making a string distinction between the name of a variable and the structure of the variable. Assignment copies the contents of one structure to another, while binding changes what structure a variable name refers to.

Replies are listed 'Best First'.
Re: Re: Exegesis 6 - Named binding
by dragonchild (Archbishop) on Jul 31, 2003 at 16:01 UTC
    This actually brings up another question - Will there be an equality operator that distinguishes between value equality and binding equality? For example, I want to know if $who is bound to $because vs. $who being == or eq to $because ...

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      Last I knew the decision was that testing for identity wasn't going to be common enough to warrant an operator. I think instead there'll be some UNIVERSAL method that returns a unique widget that you can use to test--.is or .ref, or something along those lines.
        Of course, given that we'll have macros, we should be able to code up an operator that will test for this, right?

        ------
        We are the carpenters and bricklayers of the Information Age.

        The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

        Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

        Last I heard, that function was going to be called .id, but that may have changed a billion times ;)

        T I M T O W T D I

      In Perl 5 you can already use \$x == \$y to test whether $x and $y are aliases of each other. I would think such would also work in Perl 6 but I don't follow Perl 6 deeply so I could certainly be wrong.

                      - tye
Re: Re: Exegesis 6 - Named binding
by Cine (Friar) on Jul 31, 2003 at 14:19 UTC
    Ups, wrong choice of words. Offcourse meant to write bound after all I am using the binding operator :=.

    T I M T O W T D I
      Then the answer's yes--because the key has the same name as the variable on the left side of the assignment that key's value is bound to the variable. That's how it's supposed to work, as it means you don't have to rely on hash ordering or manual looping over the RHS. It's essentially named arguments for binding, though I can see cases where it wouldn't necessarily be what you want to do...