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 66c274c1 for ; Sat, 7 Sep 2019 18:11:24 +0000 (UTC) Received: (qmail 15147 invoked by alias); 7 Sep 2019 18:11:16 -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: 44740 Received: (qmail 10892 invoked by uid 1010); 7 Sep 2019 18:11:16 -0000 X-Qmail-Scanner-Diagnostics: from mail-vk1-f195.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.221.195):SA:0(-2.0/5.0):. Processed in 2.676834 secs); 07 Sep 2019 18:11:16 -0000 X-Envelope-From: sgniazdowski@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.221.195 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=wPt9jSriPtxe6bJv9Fn+Ey3CMT9GTysd3Wbt9ngusJU=; b=VpIHo2xNL0dJNh2c2bmqt7yFYAeaZzynKVdcUDoJTzca5NE9KqfORjdeiLMlyofKs+ EkTcTeby9GT5IqQlodK1ACcp3ulIeUMCkkaOeZ6OuO58xVehCCBKSXHsToA9y9S8SwPD Hk6ZRTddRwqufYg5R4hlEdtvl0wiZqCRlWcBGuC8KLLHC9fvWIsaWeRd53c4Wj/GvDHD XO7+/WGbPeWrQkDFj/XTEvWOWpEJB0/nfGf8VKz3n37jny+/FnOWGWSxPD8L886u+3QC 8A2kM6iT/Y+N8EKPNCAJKiOOfmSHCqGHIC+NyqV9VB7poGYh9/4uQXihDyVqsdjNNeDS xXDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=wPt9jSriPtxe6bJv9Fn+Ey3CMT9GTysd3Wbt9ngusJU=; b=DW3o9ENcLCh2ZCbhQJWm+upPb885QB19iYg17DOSn6xchhqFGEViNm7kwUwNg/lyZY gvDrrXEv0rY2cnirGerjicUsYMx7Ikt2mEs2pwHkd+nLFnx3FYr2k+IWLC/CIEJp5DkQ 2nzwSX5iSuSpiPc6V7sblMWuZJsImN6lXq+OjO+mE7q/0kUswVNEvbBUGOwPM5nsFzAW EnC4dQzaGeRUiojX7Hs8x17eIk1mZ4rFj7+eLHInDXRj3M+JJFC6jgRwD1zTXXonoOVf KtTWrYYE0U5SJLqq3L5yetl5QAyA5abiK3ZjzYz0AkGeZNJIWwnYQHqh0/xXoFY2LcW9 sGOQ== X-Gm-Message-State: APjAAAWK3nwH1FsiSu8AlNaNr+9ji7X738iNwd8YA9554vLE2I2chXw8 gRmhRp6GfPVNRiVETx7NCUY0P1YoQHdRO4iz5Hk= X-Google-Smtp-Source: APXvYqxdn8IptUYLE6VKPwbueSO/TVnEtH8MJV7GHkLcAieTMwlY52HWN+dmN7KWTqN52NHv5IsxSK5x2jcLZ0XbGvk= X-Received: by 2002:a1f:a4c5:: with SMTP id n188mr7336723vke.11.1567879838278; Sat, 07 Sep 2019 11:10:38 -0700 (PDT) MIME-Version: 1.0 References: <20190907150741.jwztdoslrvk5j7nk@chaz.gmail.com> In-Reply-To: <20190907150741.jwztdoslrvk5j7nk@chaz.gmail.com> From: Sebastian Gniazdowski Date: Sat, 7 Sep 2019 20:09:57 +0200 Message-ID: Subject: Re: [PATCH] Support the mksh's ${|func;} substitution To: Sebastian Gniazdowski , Zsh hackers list Content-Type: text/plain; charset="UTF-8" On Sat, 7 Sep 2019 at 17:07, Stephane Chazelas wrote: > Note that mksh's operator can do ${|REPLY=value}, it's not > limited to functions. Ok, true, it can also run binary commands. > The ; is also not necessary I think that this is undocumented feature, as the docs say: "Another variant of substitution are the valsubs (value substitutions) ${|command;} which are also executed in the current environment, like funsubs, but share their I/O with the parent; instead, they evaluate to whatever the, initially empty, expression-local variable REPLY is set to within the commands." > 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 That's a valid and nice point, and it does yield some concerns, however for any problems to appear the user would have to have at least a function with "targetvariable=..." in name, i.e. a coincidence of two places in code, the targetvar= in the ${|...;} and in the function name, and this can be controlled and seems unlikely to occur by accident. > 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. The parsing would have to be changed to prevent the "=" in function names? I think that I've chosen an initial wrong direction: to implement the substitution "as-is", with it's form, treating it as a model. Instead, I should have implemented the feature, not the substitution. Zsh has its own ways to set-up complex substitutions and this is done via the parens flags. Would you consider such method, i.e. to not impose mksh's substitution ways on Zsh, but instead assign a flag, like e.g.: ${(|)funct}, still useful? > 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). That's interesting, it actually allows to do: arr=( val1 val2 abc1 abc3 ) funct() { REPLY="${(C)MATCH}"; } zsh_directory_name() { ... } print -rl ${arr[@]//(#m)*/${${${(D):-//funct}#\~\[}%\]}} Output: Val1 Val2 Abc1 Abc3 -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org