On Wed, Jan 29, 2003 at 02:13:34PM -0600, Jonathan Scott Duff wrote:
> On Wed, Jan 29, 2003 at 12:00:33PM -0800, Mark Biggar wrote:
> > In my opinion, default values for arrays should only come into play
> > for array elements that have NEVER been assigned to or that have
> > been explicity undef'ed.  If an assigment is made to an array element
> > then the array element should end up the assigned value (modulo
> > necessary type conversions) and the array's default value should
> > not play any part in the assignment.  After an explisit assignment
> > of an array element the only way that the array's default value
> > should magically reappear is if an undef of the element is done.
> 
> Exactly!

This means that C<@a[2] = undef> is different to C<undef @a[2]>.  This
is undesirable, but could be solved by using C<delete @a[2]>.

So, there appear to be two internally consistent ways of doing this:

  1.  There is a difference between an undefined element and a non
      existent element.  Elements are autovivified to the default value,
      their existence may be tested for with C<exists> and they may be
      deleted with C<delete>.  Undefined values may be read and written.

  2.  Attempting to read or write undef will substitute the default
      value.

Both approaches seem valid.  Choose one.  Or two.  No, one.

Note that both approaches are consistent with the way things are in Perl
5 now if you consider the default value always to be undef.  Both
approaches can also be extended to hashes.

I think the question of what to do with int arrays is somewhat separate.
Might I suggest that storing undef in an int array is not appropriate,
and thus having a (user defined) default value in an int array is also
not appropriate.  If you want power, you have to pay for it.

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

Reply via email to