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

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)
  • Comment on Re^4: [Perl 6] $ and @ - what is it coming to?

Replies are listed 'Best First'.
Re^5: [Perl 6] $ and @ - what is it coming to?
by BrowserUk (Patriarch) on Mar 26, 2008 at 19:34 UTC

    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

        Bingo.

        Do I take it that is not agreement?

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

        So, you are advocating instead of say:

        @data[ @ordered[ 0, -1 ] ] = @data[ @ordered[ -1, 0 ] ];

        something like this?:

        @data.setSlice( items_to_set => [ @ordered.getSlice( 0, @ordered.last ) ], values_to_set => [ @data.getSlice( @ordered.getSlice( @ordered.las +t, 0 ) ], );

        Because if you are, it strikes me that is moving much further away from both the syntax and spirit of Perl than the minor correction of the historical inconsistency that you are up in arms about.

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

        What if an Object is a collection class of some kind? And it only is useful on the top-level, as anything already inside another collection is a scalar.

        The elements of a collection are always scalars. There is no ambiguity there.

        When I first came to Perl, the unique requirement to use a different sigil when referring to an individual element of a collection, than when referring to the whole collection, or part thereof, was one of the most confusing things I encountered. Totally different from any other language I had used. And from what I've seen here I do not think I am unique in that. Sure you get used to it, but it never made much sense (to me).

        For example, there is the whole dichotomy of this (an empty slice) being perfectly legal and useful:

        ## an empty slice at runtime c:\test>perl -mstrict -wle"my @a='a'..'z'; print @a[ grep $_ == 10, 1. +.9 ];" ## no output and no errors

        And this being illegal:

        ## an empty slice at compile time c:\test>perl -mstrict -wle"my @a='a'..'z'; print @a[ ];" Scalar value @a[ ] better written as $a[ ] at -e line 1. syntax error at -e line 1, near "[ ]" Execution of -e aborted due to compilation errors.

        Same for one-element slice:

        ## a slice of one element at runtime c:\test>perl -mstrict -wle"my @a='a'..'z'; print @a[ grep $_ == 5, 1.. +9 ];" f

        And this being illegal:

        ## a slice of one element at compile time c:\test>perl -mstrict -wle"my @a='a'..'z'; print @a[ 5 ];" Scalar value @a[ 5 ] better written as $a[ 5 ] at -e line 1. f

        Both are inconsistent and illogical. It is making a distinction between zero or single element lists and a multi-element lists, when there should be none.


        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.