develooper Front page | perl.perl5.porters | Postings from August 2013

Re: postfix dereference syntax

Thread Previous | Thread Next
From:
demerphq
Date:
August 15, 2013 18:35
Subject:
Re: postfix dereference syntax
Message ID:
CANgJU+XocFkwZufHaVNY4HRJ+5tT06fYCgY2aPMuay06AuRfoQ@mail.gmail.com
On 15 August 2013 20:10, Johan Vromans <jvromans@squirrel.nl> wrote:
> demerphq <demerphq@gmail.com> writes:
>
>> This aside I think there is a real problem with this proposal. It
>> breaks the original model of sigils completely. IMO sigils are hard
>> enough that completely breaking the original intent is not helpful, no
>> matter how sweet your tooth is for the syntactic sugar it offers.
>>
>> My understanding of the Perl5 sigils is that they are meant to denote
>> the type of result that will be _returned_*.
>>
>> We write:
>>
>>    $thing= $foo[1];
>>
>> and not
>>
>>    $thing= @foo[1];
>>
>> because the former tells us we are getting back a scalar. The latter
>> says we are getting back a list.
>> [...]
>> * I looked for documentation to back this up, and the best I could
>> find was in perlfaq4. I suspect that it is better documented in one of
>> the Perl books by Larry.
>
> From the first Camel:
>
>   You'll note that we didn't have to tell Perl what kind of variable
>   $answer is. That's because the $ character itself tells Perl that
>   $answer can hold a single value, which can be either a string or a
>   number. We call this a scalar variable.
>
> Also:
>
>   We use the $ in $ARRAY[SCALAR] to indicate that we are selecting a
>   scalar value even though it's coming from an array that is named
>   @ARRAY. That will be confusing to you until you discover that you can
>   use @ in @ARRAY[LIST] as the notation for array slices, and you figure
>   out that the $ or @ is controlling the context of the subscript.
>
> Camel I didn't mention sigils, it called them "funny characters":
>
>   Some consider that having the variables all start with funny
>   characters makes Perl an ugly language. [...]
>
> Camel IV was the first book to call them "sigils".
>
>   Note that we do not have to be very specific about kind of variable
>   $phrase is. The $ character tells Perl that phrase is a scalar
>   variable, that is, one con- taining a singular value. An array
>   variable, by contrast, would start with an @ character. [...] Perl has
>   some other variable types, with unlikely names like “hash”, “handle”,
>   and “typeglob”. Like scalars and arrays, these types of variables are
>   also preceded by funny characters, commonly known as sigils.
>
> Also, from Camel IV:
>
>   Array subscripts are enclosed in square brackets [like this], so if
>   you want to select an individual array element, you would refer to it
>   as $home[n], where n is the subscript (one less than the element
>   number) you want. See the example that follows. Since the element you
>   are dealing with is a scalar, you always precede it with a $.
>
> Note the last sentence. This is fundamental to Perl as we know it, and
> also one of the fundamental differences between Perl and Perl6.

Thanks, so this proposal will make a lie out of every Camel book in existence.

That is not a good thing.

Yves
-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About