[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: exists $foo[7] and delete $foo[7]



On Thu, 13 Jan 2000 02:18:32 EST, Mark-Jason Dominus wrote:
>
>> Starting to fix some pesky artificial limitation in pseudo-hashes
>> that I happened to bump into, I ended up having to hack in support
>> for delete() and exists() on arrays.  Comments welcome.
>
>I notice that although the effect of deleting the last element of an
>array is documented, you have not documented the behavior of delete on
>any other element.  You only said that it `deletes' the elemnt, which
>could mean any of several things.  In particular, you did not say
>whether or not it is the same as `undef' in these cases.  I think you
>should explicitly say whether it is the same as undef or splice or
>whatever.

Basically, delete($foo[7]) makes Perl think $foo[7] is uninitialized,
which is a different state than what results from either C<$foo[7] = undef>
or C<undef $foo[7]>.  This uninitialized state couldn't be detected
in earlier versions, but now can be tested with exists().

A simpler way to put it is to say: delete($foo[7]) makes a subsequent
exists($foo[7]) return false.

>Simiarly, I think you should have a clear statement about what
>`exists' actually does for arrays.  Is  exists($a[$n]) equivalent to
>($n >= 0 ? $n <= $#a : -$n <= @a), or what?

The effect of exists() on an array element cannot be represented using
existing semantics, because the concept of "uninitialized array element"
wasn't visible at the Perl level before.  But the concept is crucial
for representing "sparseness" in arrays, which is needed by pseudo-hashes.

Feel free to suggest alternate wording if you can think of a good
way to describe it.  I'm just a code monkey. :-)


Sarathy
gsar@ActiveState.com


Follow-Ups from:
Mark-Jason Dominus <mjd@plover.com>
References to:
Mark-Jason Dominus <mjd@plover.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]