Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Support the mksh's ${|func;} substitution



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