On Thursday, January 30, 2003, at 09:55  AM, Dan Sugalski wrote:

At 9:53 AM -0800 1/30/03, Michael Lazzaro wrote:
This is leading me to the conclusion that primitive-typed arrays should not be allowed to have defaults, period, and that attempting to place one should be a compile-time error. If you want a default, use C<Int> instead of an C<int>, and it will work fine.
This isn't necessarily an issue for low-level arrays/hashes. We've got to fill the new elements with something when we extend internal structures, so there's no reason not to set the default. Doesn't mean the default should be a value that can fall outside the range that's OK for the low-level type, but...
Right, we just can't do the 'undef' thing. OK, so let me see if this is right yet:

my Int @a is default(2);
@a[5] = 5;

@a[4]; # 2 (autofilled)
@a[5]; # 5
@a[6]; # 2 (out-of-bounds)

undef @a[5]; # undefining the element sets it to the default
@a[5]; # 2

@a[5] = undef; # same as above
@a[5]; # 2


my int @a is default(2);

@a[4]; # 2 (autofilled)
@a[5]; # 5
@a[6]; # 2 (out-of-bounds)

undef @a[5]; # 0 (Warning: using undef in int context, autoconv to 0)
@a[5] = undef; # 0 (Warning: using undef in int context, autoconv to 0)
@a[5]; # 0

@a[5] = 0; # nothing special about this
@a[5]; # 0

Can everyone buy that?

MikeL



Reply via email to