Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Associative array ordering and selective unset (Re: Example function)



"Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx> writes:

> On Feb 1, 11:48am, Sven Wischnowsky wrote:
> } Subject: Re: Example function
> }
> } I was thinking about this... we could make the code keep a counter in
> } assoc arrays, increment it whenever a new key is added and store the
> } current value in the structure for this new element. Then we can treat 
> } the whole thing as being sorted by `time of addition'.
> } 
> } Hm, does this sound like the right thing?
> 
> Almost.  Something about it doesn't seem quite right to me, but I
> can't put my finger on what different behavior I'd expect.

It would be a bit tricky to reorder the associative array, wouldn't
it?  i.e., if I set up some configuration, and then want to insert
some pattern before some others, then I'd need to recreate the
associative array.  Maybe that's OK, but it feels a bit awkward.

Emacs (and other Lisps) has assoc-lists, which is maybe a better model
for this: they're explicitly lists (so they have ordering), but you
can access them by key.  I've no idea how this would map onto a shell,
but perhaps this is saying that associative arrays don't quite fit
what's wanted.

> I don't like the idea that every parameter table hash would end up
> with another integer of overhead in every entry, but maybe that's
> not so bad.

I agree, the extra integer is probably trivial.



Messages sorted by: Reverse Date, Date, Thread, Author