Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Support the mksh's ${|func;} substitution
- X-seq: zsh-workers 51902
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Lawrence Velázquez <larryv@xxxxxxx>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: [PATCH] Support the mksh's ${|func;} substitution
- Date: Tue, 4 Jul 2023 22:32:34 -0700
- Archived-at: <https://zsh.org/workers/51902>
- In-reply-to: <e27c46cc-eeca-4f90-a5b1-d1f0f1fb0743@app.fastmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAKc7PVB9EHmNS9mL00iwZbNDeZOawBL_TWV=RYnZaNYacUTphQ@mail.gmail.com> <CAH+w=7Y1xZy1B21rD-zn+oAtBayK=StxitQ7BEWTjDbNopf=RA@mail.gmail.com> <e27c46cc-eeca-4f90-a5b1-d1f0f1fb0743@app.fastmail.com>
On Tue, Jul 4, 2023 at 11:54 AM Lawrence Velázquez <larryv@xxxxxxx> wrote:
>
> For reference/comparison, a similar feature was recently added to
> bash's devel branch:
>
> https://lists.gnu.org/archive/html/bug-bash/2023-05/msg00042.html
Hmm, some interesting things from there --
-- REPLY is treated as a local, i.e., it's value gets saved and
restored around the substitution, and it's implied mksh does the same.
Zsh never does that anywhere; are there other places (in other shells)
where REPLY implicitly behaves like that?
-- "local" works inside the substitution as it would inside a function
body, but $@ refers to the calling environment.
-- "return" also behaves as if in a function body.
-- Robert Elz noticed that mksh will allow ${|foo} rather than
${|foo;} and Chet calls that a bug ... I suspect both zsh and mksh
consider allowing { foo } rather than { foo; } to be a feature, and
this "bug" is merely a reflection of that?
-- it's really not possible to implement ${(command)} in zsh because
${(flags)param} is already valid syntax, and this would break some
scripts that try to be zsh and bash at once. Chet says he's going to
require ${ (command); } instead, though.
-- ${ command; } is implemented using an anonymous tempfile rather
than something like Perl's IO::String. (Whew.)
The first three of those are implementable within the structure of the
patch from workers/51898 although it's a little messy because of the
multiple "return" points in paramsubst(). The anonymous tempfile for
the last one requires some extra stuff.
The trick with "local" vs. $@ actually might address some of the
points raised by Oliver in past discussion about the "private" module.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author