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 Date: Tue, 2 Feb 1999 08:52:20 +0100 (MET) Message-Id: <199902020752.IAA08445@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.auc.dk In-reply-to: "Bart Schaefer"'s message of Mon, 1 Feb 1999 09:02:46 -0800 Subject: Re: Associative array ordering and selective unset (Re: Example function) X-Mailing-List: 5157 Bart Schaefer wrote: > ... > > 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 > } Since even `vared' can now understand the subscripted syntax, I think adding this to unset (even in C) would be a good thing. (I'm pretty sure people will want to have a easy way to remove key/value-pairs from associative arrays). > 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. When implementing the new completion example stuff I was somewhat irritated that there is no easy way to get the value of a parameter of which one only has the name in another parameter. Trying to get the type of that parameter is indeed even more complicated. Hm, `(e)' is used at the very end and I wouldn't like to change that. Maybe yet another flag? E.g.: `P' makes the thing after the flags be used as the name of a parameter. So `${(P)foo}' is the same as `$foo', but `${(P)${foo}}' will take the value of `foo' as the name of a parameter and work on it. So your example would become: if [[ $#arg > 1 && ${(Pt)${argv[1]}} == association ]] ... Looking at the code this doesn't seem too hard to implement (well, I said `seem'...). Bye Sven -- Sven Wischnowsky wischnow@informatik.hu-berlin.de