[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 07:47:34 PST, Larry Wall wrote:
>Mark-Jason Dominus writes:
>: Could you explain why? Because I don't understand the cruciality, and
>: it seems like a very bad idea to me. In particular, I would have
>: thought that this:
>:
>: > We're officially in the beta-building phase now, and I'm going to
>: > focus on making 5.5.64 as feature-complete as possible to call it
>: > a beta. To do that, we need to pull together all the loose ends
>: > in the _existing_ features; if any of you have brand new feature
>: > ideas that haven't yet been aired, it is probably wise to keep them
>: > for 5.7.x.
>:
>: would apply to anyone who wanted to make a basic change to the
>: semantics of arrays, and I don't understand why it doesn't.
>
>It isn't a change, in the sense that this doesn't break anything, since
>you couldn't use exists() and delete() on an array at all before. If
>those verbs are to have meaning on arrays, this meaning is as good as
>any. So I guess I don't much care whether there's an immediate "why".
>
>I've generally found Sarathy's tastes to be impeccable, though everyone's
>tastes need pecking now and then.
Thanks for the confidence Larry, but I think Mark-Jason is quite right
in wanting to know how this "fits". I'll try to explain.
I've given quite a bit of thought to help pseudo-hashes out of the
"experimental" pit, and it seems to me they expose the differences
in the array/hash duality to the surface.
In particular, when you did an exists($pseudohash{foo}) in perl 5.005,
it used to report the same thing as exists($pseudohash[0]{foo}), rather
than whether the corresponding array element was there or not.
We recently changed that behavior to make exists look at the
uninitialized state of the array element and report that instead. This
leads to a condition where once you initialize a pseudo-hash element,
you can not make it go back to its uninitialized state (i.e. the condition
where the exists() will return false again) which is possible for plain
hashes.
The second problem was that delete($pseudohash{foo}) was prohibited,
for no good reason.
I fixed the two problems by adding a avhv_delete_ent(), and suddenly
realized you could do the exists() and delete() operations now on
pseudo-hashes but not on real arrays (even though pseudo-hashes are
little more than real arrays). If these operations were extended
to arrays, several things become simultaneously possible:
* consistency in how the delete() and exists() operators work
across hashes, arrays, and pseudo-hashes
* cleaner internal implementation of pseudo-hashes
* delete(), in particular, affords the ability to reclaim compact
storage in arrays, which the efficiency hounds will appreciate
* semantically, arrays are little more than efficient ordered
hashes; I therefore see delete() and exists() not working on
arrays as an arbitrary limit, and this gets rid of that limit
So I decided to should extend exists() and delete() to cover arrays
as well.
I should note that I'm not particularly attached to this going in for
5.6. Maybe we should take a vote on whether we want to keep it or
not. I think I've already cast my vote by putting it in. :-)
Sarathy
gsar@ActiveState.com
- Follow-Ups from:
-
Ronald J Kimball <rjk@linguist.dartmouth.edu>
Sam Tregar <sam@tregar.com>
Hugo <hv@crypt.compulink.co.uk>
Ilya Zakharevich <ilya@math.ohio-state.edu>
- References to:
-
Larry Wall <larry@wall.org>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]