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 8e64fb84 for ; Tue, 10 Sep 2019 02:21:46 +0000 (UTC) Received: (qmail 12988 invoked by alias); 10 Sep 2019 02:21:39 -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: 44744 Received: (qmail 19055 invoked by uid 1010); 10 Sep 2019 02:21:39 -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/25566. spamassassin: 3.4.2. Clear:RC:0(209.85.221.195):SA:0(-2.0/5.0):. Processed in 4.690821 secs); 10 Sep 2019 02:21:39 -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 :content-transfer-encoding; bh=cS8L8L9pnBstRMh2fGXJKBwF5l/7OaUjmwnlOy2AVZ8=; b=Uc3PBOJB0UlJdJIDAarcQ9Q103FY6aDOKGvouw2QwD3HQWqBJA4297V2spsdcwAN1V ALkhT8sGsedhMdWy5GFeOOp5ICicqRQgEs2SiWJk0/tAKtAQKt6dQ8HznnTjcgO4/Y2L oJqxK6G92CF+SSSmvUPKdJP/6yPmmTppRa2uF/ZvzXsX/OqPC0YLgOkd1nDERdeqDgjt Yb+V4iEjgdvbqddgTNFSN6aG29VGvIjaht8lOBVMpAVi5jhq4ktnhji4z80RNlauncKs lYKAM5ULwQqyEbqTjoIV+eqCcMjP2mQMeEROqEvW39swhKfwhFAZKY3yNYbWJx47V+NA U3LA== 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:content-transfer-encoding; bh=cS8L8L9pnBstRMh2fGXJKBwF5l/7OaUjmwnlOy2AVZ8=; b=B83F8XNlHBZ1+xxwiY1NjOwV5xYHWnMX8BNW5rcUC2DU4JorCQlH4iOKZeiOuGeGiL 7ZShdVlwu/jBA509mbN2fZ2KAKaAGp4K2tzZ9wgUWBVimIBRahQ/eTuDGPtGyszEx4D9 ywb3YIgFe6ZPcr7Is20AMv78OAUbIsyzFkjie2WFdG9qdEO8Fkt8D4uLF6KOzC2MrDuC 43Fyketa0e9B2pX0QBIgYsrI9p1pP8GRs7mDWVVTu9HcqM3sgQ2ajJs2Zt+vw/k8So6b Hs8aUVm8LwbBb8/ucBKCE+2zRtSJP1IKol+nGd4EEWVCaUz+7bvEZryGzO/3/qAYd+6H sGmw== X-Gm-Message-State: APjAAAVkXpHrq7bXu4LyoLg6Ut1sup5AIEY/e+Kv1nxWYedFaT1QZ0lg ukCeHq7YhzYnZzsmot64ehjSIcjeOsle7W05CLC4wFBoXvk= X-Google-Smtp-Source: APXvYqyP+HZq/JJpGMGW1xFbTc+8k2b03rYig52k3VTlzwaty6Z5gZ8eCw+sZhFl1kDepixUF8hcrmi1mHjO2GO1n3c= X-Received: by 2002:a1f:19d8:: with SMTP id 207mr9550321vkz.54.1568082059708; Mon, 09 Sep 2019 19:20:59 -0700 (PDT) MIME-Version: 1.0 References: <20190907150741.jwztdoslrvk5j7nk@chaz.gmail.com> <20190907201954.dn2nve65wqk4muvc@chaz.gmail.com> In-Reply-To: From: Sebastian Gniazdowski Date: Tue, 10 Sep 2019 04:20:20 +0200 Message-ID: Subject: Re: [PATCH] Support the mksh's ${|func;} substitution To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I thought that I ask: should I continue working on the feature? I.e. does it have a chance of being accepted? The feature would be: a new substitution flag (x for execute, or | to mark similarity to mksh's ${|code;}) that would execute the provided code and substitute the value of $REPLY. E.g.: - var=3D'REPLY=3Dtest'; echo ${(x)var} -> test - echo ${(x):-REPLY=3Dtest2} -> test2 - noglob print -rl ${(x):-for val (test test3) { REPLY=3D\$val }} -> test3 The usefulness is the ability to map code onto array elements (with (#m) or (#b) flags) and general lambda-like use-case. On Sat, 7 Sep 2019 at 23:19, Sebastian Gniazdowski wrote: > > On Sat, 7 Sep 2019 at 22:19, Stephane Chazelas > wrote: > > > > 2019-09-07 20:09:57 +0200, Sebastian Gniazdowski: > > > The parsing would have to be changed to prevent the "=3D" in function= names? > > [...] > > > > No, I meant that you'd need the parser to handle that case of a > > pseudo-command group (a {any shell code here} but with {| > > instead of {)). > > > > So you can do: > > > > echo ${| > > whatever $(...) > > for i do > > ... > > done} > > > > Whether it would actually be difficult or not I can't comment, > > I've not looked at the parser code. > > I think that it's already supported with the single exception that } > would have to be quoted: > > % print ${| > whatever $(...) > for i do > ... > done;} > zsh: no such function: \n whatever $(...)\n for i do\n ...\n done > > > Having an operator that *only* invokes a function to do an > > expansion is less useful IMO. That just sound like a very > > limited form of command substitution where you could have done a > > more complete form by allowing any code instead of just one > > function invocation without argument. > > Ok, I agree, the lambda-function reminiscent version is better. It > also isn't much harder to implement =E2=80=93 instead of the doshfunc() j= ust > bin_eval() would have to be called. I attach such patch. However, it > has some problems: > > arr=3D( val1 val2 abc1 abc3 ) > print ${arr[@]//(#b)(*)/${|REPLY\=3Dtest;}} > Output:test test test test > > So the =3D has to be quoted. Also, not much more works. REPLY\=3D$MATCH > nor REPLY\=3D\$MATCH are working. I wonder why, as it doesn't look that > bad in general: > > whatever() { echo func ran; } > echo ${| > whatever $(...) > for i in a b c; do > REPLY\=3D1 > done;} > > Output: > func ran > 1 > > -- > Sebastian Gniazdowski > News: https://twitter.com/ZdharmaI > IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin > Blog: http://zdharma.org -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org