On Tue, Jan 28, 2003 at 04:07:17PM -0500, Aaron Sherman wrote:

> I think this debate is easier if you think of defaults as overriding and
> auto-vivification method on a container.

Hmm.  I don't :-)

I think it is easier if you think of defaults as overriding undef.

> On Tue, 2003-01-28 at 14:47, Paul Johnson wrote:
> > Michael Lazzaro said:
> 
> > > 2a) When a cell is explicitly re-undefined, does the default value take
> > > effect?
> > >
> > >      my @a is Array( default => 'foo' ) = (1,2,3);
> > >
> > >      @a[1] = undef;
> > >      @a[1];         # undef, or 'foo'?
> > >
> > >     STRAWMAN ANSWER: 'foo'.
> > 
> > Seems right to me.  Anything else would be very confusing, I think.
> 
> This would be very confusing to me. In fact, it seems WRONG to me unless
> we're saying that such arrays can simply never hold an undefined
> value... which again seems wrong.

I think that seems right.

>         my @a is Array ( default => 'foo' );
>         @a[1] = undef;
> 
> Should yield the following, I would think:
> 
>         ('foo', undef, 'foo' x Inf)
>         
> Though, obviously there's no such thing as @a[2], but if you reference
> it, that's how it would auto-vivify.
> 
> If that's not the case, I need to get my head around why, since Perl
> *does* distinguish between defined and exists.

But I wish it wouldn't for arrays.  That only came about to support
pseudo-hashes which are going / have gone away.

Are you suggesting that hashes should also have a default?  That would
seem consistent and at least as useful as arrays having a default.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

Reply via email to