develooper Front page | perl.perl6.language | Postings from March 2005

Re: Parameter and trait questions - just how 'only' _is_ 'read-only'?

Thread Previous | Thread Next
From:
Larry Wall
Date:
March 26, 2005 16:55
Subject:
Re: Parameter and trait questions - just how 'only' _is_ 'read-only'?
Message ID:
20050327005447.GB22991@wall.org
On Sat, Mar 26, 2005 at 03:45:30PM -0500, Chip Salzenberg wrote:
: According to Rod Adams:
: > Chip Salzenberg wrote:
: > >* As far as I can tell, the choice of spelling an array parameter
: > >  C<Array @a> or C<Array $a> is entirely cosmetic: both @a and
: > >  $a are capable of holding an Array reference.  Is there actually
: > >  a difference, e.g. in how they handle an undefined value?
: >
: > Uhm... It was my impression that one of those creates an Array of 
: > Arrays, and the other just an Array.
: 
: Ah, my question had a bug.  What I meant was:
: 
:  * As far as I can tell, the choice of spelling an array parameter
:    C<@a> or C<Array $a> is entirely cosmetic: both @a and $a are
:    capable of holding an Array reference.  Is there actually a
:    difference, e.g. in how they handle an undefined value?

Not really.  The main difference is that @a will flatten in a list
context, and $a won't.

That being said, in Perl 5, if you say

    @a = undef;

you don't get an undefined array.  I'd like to make undef smart enough
about list contexts that @a actually does end up undefined in Perl 6.
That is, in scalar context, undef is a scalar value as in Perl 5, but
in Perl 6, undef in list context means "there isn't anything here if
you try to look for it", so it's more like () in Perl 5, except that
it also undefines the array if it's the only thing in the array.

I don't know if that's an entirely consistent semantics, but I'd rather
have a little inconsistency and preserve error informaiton for later
debugging whenever possible, and that undef you tried to initialize the
array with might have some interesting commentary in it.  (Though, of
course, my example above is a rather boring value of undef.)

Larry

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