develooper Front page | perl.perl6.language | Postings from January 2003

Re: Arrays: Default Values

From:
Nicholas Clark
Date:
January 28, 2003 13:17
Subject:
Re: Arrays: Default Values
Message ID:
20030128210106.GB283@Bagpuss.unfortu.net
On Tue, Jan 28, 2003 at 12:30:41PM -0800, Austin Hastings wrote:
> 
> --- Michael Lazzaro <mlazzaro@cognitivity.com> wrote:

> >      my int @a is Array( default => 5 );

> >      @a[0] = undef;
> 
> This should cause a blip of some kind. If storing an explicit undef (as
> opposed to "undef but 0" or C<$v = undef; @a[0] = $v;> there should be
> an exception. If storing an implicit undef: convert to int (IOW: 0) and
> emit a warning.
> 
> >      @a[0];         # 0, or 5?

I'm not sure. I think I like the idea of

  @a[0] = undef;

being a blip, but

  undef @a[0];

resetting the value to the default. Conceptually perl5 already has a
distinction between assigning undef to an aggregate, and passing an
aggregate to the undef operator:

$ perl -le '@a = %ENV; print scalar @a; undef @a; print scalar @a'
42
0
$ perl -le '@a = %ENV; print scalar @a; @a = undef; print scalar @a'
42
1

so it's not a great leap to extend this difference to scalar values.
Although it may be one leap too far.

Nicholas Clark



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