* 'K' subscript flag with associative array?
@ 2011-03-01 16:50 Greg Klanderman
2011-03-01 17:09 ` Mikael Magnusson
2011-03-01 17:13 ` Benjamin R. Haskell
0 siblings, 2 replies; 6+ messages in thread
From: Greg Klanderman @ 2011-03-01 16:50 UTC (permalink / raw)
To: Zsh list
Hi guys, what am I doing wrong here? Shouldn't this:
zsh% echo ${(k)functions[(K)_*]}
give all function names starting with '_'?
It gives me nothing; the 'R' subscript flag does seem
to work for matching against the bodies of functions
and returning the names of those functions.
thanks,
Greg
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: 'K' subscript flag with associative array?
2011-03-01 16:50 'K' subscript flag with associative array? Greg Klanderman
@ 2011-03-01 17:09 ` Mikael Magnusson
2011-03-01 17:20 ` Benjamin R. Haskell
2011-03-01 18:08 ` Greg Klanderman
2011-03-01 17:13 ` Benjamin R. Haskell
1 sibling, 2 replies; 6+ messages in thread
From: Mikael Magnusson @ 2011-03-01 17:09 UTC (permalink / raw)
To: gak; +Cc: Zsh list
On 1 March 2011 17:50, Greg Klanderman <gak@klanderman.net> wrote:
>
> Hi guys, what am I doing wrong here? Shouldn't this:
>
> zsh% echo ${(k)functions[(K)_*]}
>
> give all function names starting with '_'?
>
> It gives me nothing; the 'R' subscript flag does seem
> to work for matching against the bodies of functions
> and returning the names of those functions.
>
> thanks,
> Greg
>
% echo ${(k)functions[(<tab>
---- subscript flags
I -- all keys matched by subscript as pattern
K -- all values where subscript matched by key as pattern
R -- all values matched by subscript as pattern
e -- interpret * or @ as a single key
i -- any one key matched by subscript as pattern
k -- any one value where subscript matched by key as pattern
r -- any one value matched by subscript as pattern
Ie, you want I, not K. What K/k does is somewhat weird, in that it
interprets the keys of the arrays as patterns and check which of those
match the given subscript. With I/i you don't need to specify ${(k)
either, it defaults to showing the keys, but you can give ${(v) to
instead get the values.
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: 'K' subscript flag with associative array?
2011-03-01 16:50 'K' subscript flag with associative array? Greg Klanderman
2011-03-01 17:09 ` Mikael Magnusson
@ 2011-03-01 17:13 ` Benjamin R. Haskell
1 sibling, 0 replies; 6+ messages in thread
From: Benjamin R. Haskell @ 2011-03-01 17:13 UTC (permalink / raw)
To: Greg Klanderman; +Cc: Zsh list
On Tue, 1 Mar 2011, Greg Klanderman wrote:
>
> Hi guys, what am I doing wrong here? Shouldn't this:
>
> zsh% echo ${(k)functions[(K)_*]}
>
> give all function names starting with '_'?
You want:
${functions[(I)_*]}
If I'm reading the man page right, I'd interpret your attempt as:
the list of functions whose names, when taken as patterns, match the
literal string: '_*'
K treats the keys as patterns.
Most function names don't contain pattern metachars, so when taken as
patterns, only match their own names.
But, for example:
$ '??' () { echo question everything }
$ print -l ${(k)functions[(K)_*]}
??
# because the key '??' matches any two characters
$ print -l ${(k)functions[(K)lj]}
??
Not sure what the utility is, though. Something like this, I guess?
$ typeset -A featureset
$ featureset=( '*.*' hasadot 'test.*' 'test function' )
$ print -l ${featureset[(K)lkjlkjljk.ojojojoj]}
hasadot
$ print -l ${featureset[(K)test.function]}
hasadot
test function
--
Best,
Ben
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: 'K' subscript flag with associative array?
2011-03-01 17:09 ` Mikael Magnusson
@ 2011-03-01 17:20 ` Benjamin R. Haskell
2011-03-01 17:28 ` Mikael Magnusson
2011-03-01 18:08 ` Greg Klanderman
1 sibling, 1 reply; 6+ messages in thread
From: Benjamin R. Haskell @ 2011-03-01 17:20 UTC (permalink / raw)
To: Mikael Magnusson; +Cc: Zsh list
On Tue, 1 Mar 2011, Mikael Magnusson wrote:
> % echo ${(k)functions[(<tab>
> ---- subscript flags
Tangent: how do I get the completion system to display that line?
--
Best,
Ben
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: 'K' subscript flag with associative array?
2011-03-01 17:20 ` Benjamin R. Haskell
@ 2011-03-01 17:28 ` Mikael Magnusson
0 siblings, 0 replies; 6+ messages in thread
From: Mikael Magnusson @ 2011-03-01 17:28 UTC (permalink / raw)
To: Benjamin R. Haskell; +Cc: Zsh list
On 1 March 2011 18:20, Benjamin R. Haskell <zsh@benizi.com> wrote:
> On Tue, 1 Mar 2011, Mikael Magnusson wrote:
>
>> % echo ${(k)functions[(<tab>
>> ---- subscript flags
>
> Tangent: how do I get the completion system to display that line?
I suppose it's some/one of these
zstyle ':completion:*:descriptions' format "%B---- %d%b"
zstyle ':completion:*:messages' format '%B%U---- %d%u%b'
zstyle ':completion:*:warnings' format '%B%F{9}---- no match for: %d%f%b'
zstyle ':completion:*:corrections' format '%B---- %d %F{11}(errors: %e)%f%b'
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*' separate-sections 'yes'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' prompt 'errors: %e'
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: 'K' subscript flag with associative array?
2011-03-01 17:09 ` Mikael Magnusson
2011-03-01 17:20 ` Benjamin R. Haskell
@ 2011-03-01 18:08 ` Greg Klanderman
1 sibling, 0 replies; 6+ messages in thread
From: Greg Klanderman @ 2011-03-01 18:08 UTC (permalink / raw)
To: zsh-workers
>>>>> On March 1, 2011 Mikael Magnusson <mikachu@gmail.com> wrote:
> Ie, you want I, not K.
Thanks Mikael and Ben!
> What K/k does is somewhat weird, in that it
> interprets the keys of the arrays as patterns and check which of those
> match the given subscript.
Only after reading this do I now understand what the manual is
saying..
Greg
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-03-01 18:13 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-01 16:50 'K' subscript flag with associative array? Greg Klanderman
2011-03-01 17:09 ` Mikael Magnusson
2011-03-01 17:20 ` Benjamin R. Haskell
2011-03-01 17:28 ` Mikael Magnusson
2011-03-01 18:08 ` Greg Klanderman
2011-03-01 17:13 ` Benjamin R. Haskell
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).