Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Support the mksh's ${|func;} substitution
- X-seq: zsh-workers 44744
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH] Support the mksh's ${|func;} substitution
- Date: Tue, 10 Sep 2019 04:20:20 +0200
- 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==
- In-reply-to: <CAKc7PVB-V8Gqd2Pg8X=YjQDyPC=zG3keaKtdiS8cFCgfUOT_EA@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVBTw2j=awaf0wAkyyO08k=vossU28fvZ=s+fhqMkcKuJQ@mail.gmail.com> <20190907150741.jwztdoslrvk5j7nk@chaz.gmail.com> <CAKc7PVDC6NULei7FCKXvHu1YRzhmk9ZJK4BECRRxpWNQpHCw9w@mail.gmail.com> <20190907201954.dn2nve65wqk4muvc@chaz.gmail.com> <CAKc7PVB-V8Gqd2Pg8X=YjQDyPC=zG3keaKtdiS8cFCgfUOT_EA@mail.gmail.com>
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='REPLY=test'; echo ${(x)var} -> test
- echo ${(x):-REPLY=test2} -> test2
- noglob print -rl ${(x):-for val (test test3) {
REPLY=\$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
<sgniazdowski@xxxxxxxxx> wrote:
>
> On Sat, 7 Sep 2019 at 22:19, Stephane Chazelas
> <stephane.chazelas@xxxxxxxxx> wrote:
> >
> > 2019-09-07 20:09:57 +0200, Sebastian Gniazdowski:
> > > The parsing would have to be changed to prevent the "=" 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 – instead of the doshfunc() just
> bin_eval() would have to be called. I attach such patch. However, it
> has some problems:
>
> arr=( val1 val2 abc1 abc3 )
> print ${arr[@]//(#b)(*)/${|REPLY\=test;}}
> Output:test test test test
>
> So the = has to be quoted. Also, not much more works. REPLY\=$MATCH
> nor REPLY\=\$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\=1
> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author