From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: When (K) hash subscript flag could be useful?
Date: Mon, 2 Oct 2017 09:54:37 -0700 [thread overview]
Message-ID: <171002095437.ZM20830@torch.brasslantern.com> (raw)
In-Reply-To: <etPan.59d242ba.35d2426e.98a8@zdharma.org>
On Oct 2, 3:44pm, Sebastian Gniazdowski wrote:
}
} I stumbled upon ${harr[(K)...]}. Completion says:
}
} K -- all values where subscript matched by key as pattern
}
} So this is reverse to what is expected
Er, expected by who, why?
} I suspect (K) was added for versality. But maybe there are know
} applications of such "hash = database of patterns" construct?
It allows you to build something like a "case" statement where the
branches aren't established until run time. Instead of
case $x in
(...) y=$z;;
# ... etc. ...
esac
you can write
y=${z[(K)$x]}
It's also basically the same thing that "zstyle" does with context
lookup, except that zstyle layers on special treatment of using the
"best match" to always return a single result.
next prev parent reply other threads:[~2017-10-02 16:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-02 13:44 Sebastian Gniazdowski
2017-10-02 16:54 ` Bart Schaefer [this message]
2017-10-02 17:51 ` Sebastian Gniazdowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=171002095437.ZM20830@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).