in reply to Re^2: [Perl 6] $ and @ - what is it coming to?
in thread [Perl 6] $ and @ - what is it coming to?

As best I understand it, because in Perl 6, arrays always use the '@' sigil.

So elements of @x are accessed using @x[1]

And elements of the array pointed at by $x can be accessed using $x[1].

The abiguity that is confusing you is because Perl 5 used $x[1] to access elements of array @x.

@x = ( 1, 2, 3);; print @x[1];; Scalar value @x[1] better written as $x[1] at 2

The explanation for that was that the use of the '$' signified that the element accessed was a scalar. But elements of arrays are always scalars, which makes the purpose of changing the sigil redundant. So in Perl 6 you don't.

In the same way, if it hasn't changed since I last looked, hash elements are addressed using %x{'foo'} (or %x<foo>) and not $x{'foo'} as now.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^4: [Perl 6] $ and @ - what is it coming to?
by ruzam (Curate) on Mar 26, 2008 at 19:16 UTC
    OK, thanks. I think I get it now.

    I've come to really love the way Perl identifies what you should expect to get out of the variable. It speaks to me on a "this is what I like about Perl" way. Now the emphasis seems to be on the container, not the contents which is a complete reversal. Some how that just seems like a really wrong thing to do with the language (is it even Perl anymore?). Maybe that's just a result of familiarity and I'd see it from the other side if Perl had always done it this way (shrug).
      is it even Perl anymore?

      Yes. Write some, and I suspect you'll find that Perl 6 feels very Perlish.

      Maybe that's just a result of familiarity and I'd see it from the other side if Perl had always done it this way...

      That's my guess.

Re^4: [Perl 6] $ and @ - what is it coming to?
by ruzam (Curate) on Mar 26, 2008 at 19:21 UTC
    Hey, wait a minute.

    If changing the sigil is considered redundant, then isn't leaving the '@' on it even more redundant? The array is already clearly identified by the [ ] no?

    (same comment to hashes)

      Well no. Then there would be no way to differentiate @x[1] and $x[1].

      Indeed, without the sigils it wouldn't be possible to have a scalar x and an array x and a hash x unless you also had to use the brackets and braces when referring to the container: x[] and x{}.

      But then how would you do an empty slice: @x[]?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Bingo.

        As for operations on the container, they are just member functions. Call a suitable one.

        —Johnwriting from Pudong Airport