From mboxrd@z Thu Jan 1 00:00:00 1970 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes From: "Bart Schaefer" Message-Id: <990201090246.ZM31742@candle.brasslantern.com> Date: Mon, 1 Feb 1999 09:02:46 -0800 In-Reply-To: <199902011048.LAA07559@beta.informatik.hu-berlin.de> Comments: In reply to Sven Wischnowsky "Re: Example function" (Feb 1, 11:48am) References: <199902011048.LAA07559@beta.informatik.hu-berlin.de> X-Mailer: Z-Mail (4.0b.820 20aug96) To: zsh-workers@sunsite.auc.dk Subject: Associative array ordering and selective unset (Re: Example function) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailing-List: 5153 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. 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. } P.S.: Is `foo=( ${(kv)foo[(I)^key]} )' the easiest way to remove a } key/value-pair from an associative array? Probably, if you have extendedglob set. If you don't have extendedglob, that's a moderately hard way to remove -all- the key/value pairs. We could go the ksh route and make `noglob unset foo[key]` work. Like: function unset() { emulate -R zsh setopt localoptions extendedglob local arg i for i do arg=( "${(@s:[:)i}" ) if [[ $#arg > 1 && $(eval print '${(t)'${arg[1]}'}') == association ]] then eval "$arg[1]=( \${(kv)$arg[1][(I)^${(j:[:)arg[2,-1]} )" else builtin unset $i fi done } Can you think of a better idiom than $(eval print '${(t)'${arg[1]}'}') to get the type of the variable whose name is the value of $arg[1] ? I keep thinking there ought to be a way with ${(e)...} but couldn't make it work. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com