zsh-users
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <psprint@zdharma.org>
To: Bart Schaefer <schaefer@brasslantern.com>, Zsh Users <zsh-users@zsh.org>
Subject: Re: When (K) hash subscript flag could be useful?
Date: Mon, 2 Oct 2017 19:51:34 +0200	[thread overview]
Message-ID: <etPan.59d27ca6.557aed8f.98a8@zdharma.org> (raw)
In-Reply-To: <171002095437.ZM20830@torch.brasslantern.com>

On 2 października 2017 at 18:54:37, Bart Schaefer (schaefer@brasslantern.com) wrote:
> 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 was trying to think like a regular user, when he reads about (R) for value matching, (I) for key matching, then (K) can be I think expected to be some combination of the two previous straightforward ones.
 
> 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]}

Interesting, one could even skip "y=" and call handler function, but there is a problem, undefined order, so final catch-all "*" key could be called first. Just thinking about performance of e.g. syntax-highlighting, there are large case statements there, however function call uses significant CPU time (when in long loop), so there would probably be no gain anyway.

I wasn't criticizing (K) but thinking that it's a cool tool that can solve some crucial problem(s).
--  
Sebastian Gniazdowski
psprint /at/ zdharma.org


      reply	other threads:[~2017-10-02 17:51 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
2017-10-02 17:51   ` Sebastian Gniazdowski [this message]

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=etPan.59d27ca6.557aed8f.98a8@zdharma.org \
    --to=psprint@zdharma.org \
    --cc=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).