From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id a60d5e85 for ; Sat, 7 Sep 2019 15:08:30 +0000 (UTC) Received: (qmail 1330 invoked by alias); 7 Sep 2019 15:08:22 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 44739 Received: (qmail 12493 invoked by uid 1010); 7 Sep 2019 15:08:22 -0000 X-Qmail-Scanner-Diagnostics: from mail-wm1-f67.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25559. spamassassin: 3.4.2. Clear:RC:0(209.85.128.67):SA:0(-2.0/5.0):. Processed in 2.126034 secs); 07 Sep 2019 15:08:22 -0000 X-Envelope-From: stephane.chazelas@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.128.67 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=hUv5DPI/eiPWWBHy0vWUvsPkxM6JWg/rG9J3yDbnPb8=; b=LVSaaWn31QtvBKZq7hu7YB/0/qZk90HutklO6CzOls293dK/Fao3AfRQdLPq3Sd429 NzBSOAVp/IUrKP7Y0TpKjyaV6QG0tRW/A3L11pYGecgzf0jqrhotG04M4MMPK8lUbaa1 j+Whjb2AjswvWtMIcb8shnSp9ikoTXXJw8EhDHR1wBd29h9RGkTOzsJWXMbg+BxvCumB LMOk5fXFg0n10zmvbPVYE2tVWBANz3Us2OW4AuXF/FEiLs77aLzIqhWGi3JjPF6w6JrC tqR6g0eITBdut2oA/vF3KUDzylckO5xjd3uYFPGLMyQV7NO1LCBbs73qX0wfjL7FkrCS hEhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=hUv5DPI/eiPWWBHy0vWUvsPkxM6JWg/rG9J3yDbnPb8=; b=H0+yorjD+KDs7x5q+aHArTdrIofmAan/MWwFEVDGSk0qoJSAQO3XGxZBm6ZlApKirA YKyLQEjt4XzRx6qxTVZtOZ53dfGVLaIJ6A83VbIafsj2Q7aS+J1pxpSKx0+Fki89Sb3x xdab4oiNHXyl4Vr2y585axbyOt/U+9Zy0nxJ5278RluDZ/c8QRHbNpga81UHDpJuZnoz 9Dnc1DVLQDSoDy8YXL2TdpUAnZfpcstErQwGRHyh+mXhdftLR/F3fE0XkoI+d+8xjGTg DFKfEmskeQO6CRqNHaF+ltTK1DNACoTYn+XHkdAbznAeb/qjlDPknqkSGGo05jURdSmz 86LQ== X-Gm-Message-State: APjAAAWoA6X0Venb0E4lwqCfLpUeMejP6nM2+FvvhsqrvX8pc1WFFv8M YssXY/EjCPgw9Sq93ULCz4ewnpjswEk= X-Google-Smtp-Source: APXvYqyQJfDBl2DNddhSDLELBpjC5wQtsBMQ8mBm3gRdyflxQ+xZ4VOtXu1bN4a87vIAzsuOHPz+dg== X-Received: by 2002:a1c:4383:: with SMTP id q125mr10861646wma.122.1567868863185; Sat, 07 Sep 2019 08:07:43 -0700 (PDT) Date: Sat, 7 Sep 2019 16:07:41 +0100 From: Stephane Chazelas To: Sebastian Gniazdowski Cc: Zsh hackers list Subject: Re: [PATCH] Support the mksh's ${|func;} substitution Message-ID: <20190907150741.jwztdoslrvk5j7nk@chaz.gmail.com> Mail-Followup-To: Sebastian Gniazdowski , Zsh hackers list References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20171215 2019-09-06 02:52:39 +0200, Sebastian Gniazdowski: > Hello > Some notes on the patch: > - the subst is being handled at top of paramsubst, because it's made > uncompatible with (...)-flags (${|(U)funct;} looks awful, more on this > in the patch), > - then the `s' variable is advanced past the semicolon, so that the > rest of the function can safely progress doing (almost) nothing > - one thing that the function still does is a fetchvalue, which I > prevent from setting vunset to 1 in case of ${|func;} > > If commited, the substitution will be super useful in // substitution. E.g.: > > arr=( val1 val2 abc1 abc3 ) > func() { REPLY="${(C)match[1]}"; } > print -rl ${arr[@]//(#b)(*)/${|func;}} [...] Note that mksh's operator can do ${|REPLY=value}, it's not limited to functions. The ; is also not necessary, contrary to the ${ code; } variant from ksh93 (but which mksh implements with temporary files instead of changing the whole I/O framework). Note that in zsh anything is a valid function name, just like just about anything is a valid command name. So your operator would be incompatible with mksh's if it accepted arbitrary function names unless you handled quoting in there: $ ./Src/zsh -c '"REPLY=value"() { REPLY=x; echo done; }; REPLY\=value; echo ${|REPLY=value;}' done zsh:1: no such function: REPLY=value $ ./Src/zsh -c '"REPLY=value"() { REPLY=x; echo done; }; REPLY\=value; echo ${|"REPLY=value";}' done zsh:1: no such function: "REPLY=value" So at the moment I'd say it has a few problems in that: - it doesn't accept all function names - the ; is unnecessary here - it doesn't allow arbitrary code. With those fixed, i.e. when it's really like mksh's ${|code}, I'd agree the feature could be useful, but I suspect that would be harder to implement as it would mean changing the parsing. Note that beside the math functions, zsh already has something similar with its "dynamic named directory" framework (a feature I always found quite obscure/far fetched myself). echo "${| REPLY=value}" could be done in zsh with: zsh_directory_name() { [[ $1 = d ]] && [[ $2 = //* ]] || return eval " ${2#//}" reply=("$REPLY" ${#2}) } echo ${${${(D):-//REPLY=value}#\~\[}%\]} (even more convoluted than your math function approach). -- Stephane