On Fri, Apr 11, 2008 at 12:53:31PM -0700, Bob Rogers wrote: > # New Ticket Created by Bob Rogers > # Please include the string: [perl #52778] > # in the subject line of all future correspondence about this issue. > # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=52778 > > > > As the transcript below shows, Parrot out-Perls even Perl by changing > the array length when accessing a non-existent element, and not just > when storing one. It would be easy enough to give Parrot the same > behavior as Perl, but it's not clear that that's entirely the right > thing. The real question is therefore: What's the appropriate > autovivification behavior for the resizable array base classes, which > presumably ought to be language-agnostic? > [...] > [EMAIL PROTECTED]> cat array-autoviv.pir > .sub main :main > .local pmc array > array = new 'ResizablePMCArray' > > $P0 = array[7] > > $I0 = array > print $I0 > print "\n" > .end > [EMAIL PROTECTED]> ./parrot array-autoviv.pir > 8 > [EMAIL PROTECTED]>
Short answer: The array's length should not change. Long answer: I suspect this is residual behavior from earlier implementations of RPA and friends. In particular, as recently as September 2007 arrays in Parrot would bind and return Undef PMCs for non-existent elements, such that one could do: .local pmc array array = new 'ResizablePMCArray' $P0 = array[7] # get PMC for array[7] (Undef) $P0 = 3 # set array[7] to three $P1 = array[7] # get PMC from array[7] say $P1 # displays "3\n" In other words, accessing a non-existent element vivified the element to Undef (which could then be reassigned a value) -- thus the length of the array needed to change to reflect this fact. Newer versions of Parrot now return PMCNULL for non-existent elements, making them consistent with Hash and other forms of keyed lookup. Thus, since we no longer auto-vivify on accesses to non-existent elements, I suspect the array length should not change either. Fixing this shouldn't be all that difficult -- in particular, I think that src/pmc/resizablepmcarray.pmc lines 205-206 should be changed from - if (key >= PMC_int_val(SELF)) - SELF.set_integer_native(key+1); to something like + if (key >= PMC_int_val(SELF)) + return PMCNULL; I haven't tested this -- there may be other things that need to change as well. Hope this helps, Pm