Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Support the mksh's ${|func;} substitution
On Wed, Sep 11, 2019 at 5:09 PM Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> wrote:
>
> So you've implemented ${|code;} for mksh?
Good grief, no. I have never even (knowingly) USED mksh. I just said
that IF it had been me, I probably would have made a different syntax
choice.
> On Tue, 10 Sep 2019 at 21:38, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >
> > I'm writing by analogy to the (e) glob qualifier. Consider:
> >
> > % touch 'echo HELLO WORLD; reply=HERE'
> > % print e*(e^'eval $REPLY'^)
> > HELLO WORLD
> > HERE
>
> Ok, but this could use ...RLD; REPLY=HERE'. The use of reply is just
> to simplify, i.e. to use different vars for the (x) embedded code and
> for the substitution code?
Again, by analogy to the glob qualifier -- the input ($REPLY) is a
scalar, the output ($reply) is an array (which might or might not get
string-ified by double-quoting).
In an (e) glob, REPLY is set to each possible file name in turn, but
$reply can provide multiple names to the final result. I'm assuming
you want ${(x...)array} to apply to each array element in turn, not to
the entire array at once, so again REPLY is a scalar (each array
element) but could be replaced by multiple elements in $reply.
> Ahso. So the ${(x^'eval $REPLY'^)var} in the end could be ${(x^'eval
> func^):-} ? I.e. the code to evaluate would be provided within the (x)
> delimiters, and the connection with REPLY <-> substitution value (i.e.
> $var or :-string) would be additional?
I think you grasped it, yes.
Whether the syntax ${(x+func)...} would call "func" once for each
array element (again by analogy to glob (e+func)) would be an
implementation choice. Too bad (x) for globs and (e) for parameters
already have other meanings, so there's no way to make them use the
identical key character.
> > > I think that the (x) flag should be at the top of the list, first.
> >
> > That can't be right.
>
> Ok, I've did hurry too much. The :- is point 7.
This sounds more sensible.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author