Some requests for verification, plus additional questions. If anyone
has any arguments/clarifications/questions on these, please discuss so
I can document.
1) Edge cases in array indexing:
my int @a = (1,2,3);
@a[0] # 1
@a[1] # 2
@a[2] # 3
@a[3] # undef
@a[2**128] # undef (but not exception???)
@a[Inf] # undef (but not exception)
@a[ undef ] # undef, or 1?
@a['foo'] # undef, or 1?
@a[-1] # 3
@a[-2] # 2
@a[-3] # 1
@a[-4] # undef
@a[-Inf] # undef (but not exception)
Is [undef] the same as [0] in Perl6? Is there any index value you can
give that will cause an exception?
2) As hinted above, is there a (platform-dependent) maximum addressable
array index, or do we promise to correctly handle all integers, even if
BigInt? (This might come into play for lazy/sparse arrays. Maybe.)
3) Array default values. It has been mentioned repeatedly that it
would be nice to be able to specify what the value an array cell will
contain, if it has not been previously stored to. What's the preferred
syntax? One example:
my @a is Array( default => 'foo' ); # (a) by value?
my @a is Array( default => { $_ ** 2 } ); # (b) via closure???
Note that if (b) is possible, I don't know how you'd _store_ a closure
as the default value of an array, if you're into that sort of thing.
4) Optional array behavior. In addition to default values, it may be
possible to expose other details of array behavior, such that the user
has some flexibility in the implementation of a given array. Examples:
my @a is Array(
min_size => 50, # minimum reported size of this array
max_size => 100, # maximum reported size of this array
resize => (1024), # internal blocksize (in indexes)
# by which array expands?
resize => { $_ * 2 }, # or via closure, based on current size?
exception => 1, # whether out-of-bounds addressing
# causes an exception to be thrown
exception_neg => 1, # (for negative indexes only?)
exception_pos => 1, # (for positive indexes only?)
locked => 1, # read-only, can't store new values
start_index => 0, # starting index, if not zero
);
... if such capabilities exist, what are their real names? Can
anyone think of any that are absolute must-haves? Are any of the above
must-haves?
(Note that the obvious added complexity caused by so many options can
probably be optimized away for the default array implementation.)
MikeL
- Re: More Array Behaviors Michael Lazzaro
- Re: More Array Behaviors Nicholas Clark
- Re: More Array Behaviors Austin Hastings
- Re: More Array Behaviors Nicholas Clark
- Re: More Array Behaviors Leopold Toetsch
- Re: More Array Behaviors Dave Whipp
- Re: More Array Behaviors Damian Conway
- Re: More Array Behaviors Dave Whipp
- Re: More Array Behaviors Damian Conway
- Re: More Array Behaviors Dave Whipp
- Re: More Array Behaviors Austin Hastings