* no-fork expansion with array var
@ 2023-09-22 21:00 Mikael Magnusson
2023-09-22 21:16 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2023-09-22 21:00 UTC (permalink / raw)
To: zsh-workers
The documentation says:
If param names an array, array expansion rules apply.
But what it means is if you do an array assignment to var inside the
code block, array expansion rules apply:
% typeset -a foo; print -rl - ${${|foo| foo=hi}[1]}
h
% typeset +a foo; print -rl - ${${|foo| foo=(hi)}[1]}
hi
I know that REPLY is special cased, but I also found this confusing:
% print -rl - ${|REPLY| REPLY=(hi there)} ${|REPLYY| REPLYY=(hi there)}
hi there
hi
there
restoring REPLY around the expansion shouldn't affect whether it was
returned as an array from inside the block, should it? Or we should at
least document that the special name REPLY is always expanded as a
scalar, whether it's named or used as the default name via
${|REPLY=(foo bar)}.
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: no-fork expansion with array var
2023-09-22 21:00 no-fork expansion with array var Mikael Magnusson
@ 2023-09-22 21:16 ` Bart Schaefer
2023-09-23 5:13 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2023-09-22 21:16 UTC (permalink / raw)
To: Mikael Magnusson; +Cc: Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 688 bytes --]
On Fri, Sep 22, 2023, 4:00 PM Mikael Magnusson <mikachu@gmail.com> wrote:
> The documentation says:
> If param names an array, array expansion rules apply.
>
> But what it means is if you do an array assignment to var inside the
> code block, array expansion rules apply
>
There are two cases: The parameter has already been declared an array, or
it's made an array by assignment within the expression. I was trying to
cover both, but rephrasing welcome.
Or we should at
> least document that the special name REPLY is always expanded as a
> scalar
Oops, I thought I'd mentioned that. It was certainly implied by the
descriptions of mksh behavior. Anyway that is how it works.
[-- Attachment #2: Type: text/html, Size: 1292 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: no-fork expansion with array var
2023-09-22 21:16 ` Bart Schaefer
@ 2023-09-23 5:13 ` Bart Schaefer
2023-09-23 12:46 ` Mikael Magnusson
0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2023-09-23 5:13 UTC (permalink / raw)
To: Mikael Magnusson; +Cc: Zsh hackers list
On Fri, Sep 22, 2023 at 4:16 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> On Fri, Sep 22, 2023, 4:00 PM Mikael Magnusson <mikachu@gmail.com> wrote:
>>
>> The documentation says:
>> If param names an array, array expansion rules apply.
>>
>> But what it means is if you do an array assignment to var inside the
>> code block, array expansion rules apply
How about this?
diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index 86a5f70c8..837a85db6 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -1915,8 +1915,9 @@ Substitutions of the form
`tt(${|)var(param)tt(|)...tt(})' are similar,
except that the substitution is replaced by the value of the parameter
named by var(param). No implicit save or restore applies to var(param)
except as noted for tt(REPLY), and var(param) should em(not) be declared
-within the command. If var(param) names an array, array expansion rules
-apply.
+within the command. If, after evaluating the expression, var(param)
+names an array, array expansion rules apply. However, tt(REPLY) is
+always expanded in scalar context, even if assigned an array.
A command enclosed in braces preceded by a dollar sign, and set off from
the braces by whitespace, like `tt(${ )...tt( })', is replaced by its
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: no-fork expansion with array var
2023-09-23 5:13 ` Bart Schaefer
@ 2023-09-23 12:46 ` Mikael Magnusson
0 siblings, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2023-09-23 12:46 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh hackers list
On 9/23/23, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Fri, Sep 22, 2023 at 4:16 PM Bart Schaefer <schaefer@brasslantern.com>
> wrote:
>>
>> On Fri, Sep 22, 2023, 4:00 PM Mikael Magnusson <mikachu@gmail.com> wrote:
>>>
>>> The documentation says:
>>> If param names an array, array expansion rules apply.
>>>
>>> But what it means is if you do an array assignment to var inside the
>>> code block, array expansion rules apply
>
> How about this?
>
> diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
> index 86a5f70c8..837a85db6 100644
> --- a/Doc/Zsh/expn.yo
> +++ b/Doc/Zsh/expn.yo
> @@ -1915,8 +1915,9 @@ Substitutions of the form
> `tt(${|)var(param)tt(|)...tt(})' are similar,
> except that the substitution is replaced by the value of the parameter
> named by var(param). No implicit save or restore applies to var(param)
> except as noted for tt(REPLY), and var(param) should em(not) be declared
> -within the command. If var(param) names an array, array expansion rules
> -apply.
> +within the command. If, after evaluating the expression, var(param)
> +names an array, array expansion rules apply. However, tt(REPLY) is
> +always expanded in scalar context, even if assigned an array.
>
> A command enclosed in braces preceded by a dollar sign, and set off from
> the braces by whitespace, like `tt(${ )...tt( })', is replaced by its
That works for me.
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-23 12:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-22 21:00 no-fork expansion with array var Mikael Magnusson
2023-09-22 21:16 ` Bart Schaefer
2023-09-23 5:13 ` Bart Schaefer
2023-09-23 12:46 ` Mikael Magnusson
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).