* [PATCH] Documentation on (A) Create array parameter
@ 2017-02-22 11:40 Sebastian Gniazdowski
2017-02-22 19:58 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Gniazdowski @ 2017-02-22 11:40 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 1231 bytes --]
Hello,
(A) completion and documentation suggest straight creation:
A Create an array parameter with `${...=...}', `${...:=...}'
or `${...::=...}'. If this flag is
repeated (as in `AA'), create an associative array
parameter. Assignment is made before sorting
or padding; if field splitting is active, the word part is
split before assignment. The name
part may be a subscripted range for ordinary arrays;
the word part must be converted to an
array, for example by using `${(AA)=name=...}' to activate
field splitting, when creating an
associative array.
This test:
% typeset -a overwrite_me=( 1 ); () { var_name="overwrite_me"; :
${(PA)var_name::=}; }; echo $overwrite_me"."${(t)overwrite_me}
.array
% () { local -a overwrite_me=( 1 ); () { var_name="overwrite_me"; :
${(PA)var_name::=}; }; echo $overwrite_me"."${(t)overwrite_me} }
.array-local
shows that parameter is reused if it exists, even if it exists on lower
scoping level. That's useful when coding, the patch adds one sentence
that clarifies this.
--
Sebastian Gniazdowski
psprint2@fastmail.com
[-- Attachment #2: A_create_array.diff --]
[-- Type: text/plain, Size: 615 bytes --]
diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index cf4f69e..386db08 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -964,6 +964,8 @@ assignment. The var(name) part may be a subscripted range for
ordinary arrays; the var(word) part em(must) be converted to
an array, for example by using `tt(${(AA)=)var(name)tt(=)...tt(})'
to activate field splitting, when creating an associative array.
+If the array parameter whose creation is requested already exists,
+it is reused, even when it exists at lower scoping level.
)
item(tt(a))(
Sort in array index order; when combined with `tt(O)' sort in reverse
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Documentation on (A) Create array parameter
2017-02-22 11:40 [PATCH] Documentation on (A) Create array parameter Sebastian Gniazdowski
@ 2017-02-22 19:58 ` Bart Schaefer
2017-02-22 20:47 ` Sebastian Gniazdowski
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2017-02-22 19:58 UTC (permalink / raw)
To: zsh-workers
On Feb 22, 3:40am, Sebastian Gniazdowski wrote:
}
} (A) completion and documentation suggest straight creation:
There's no such thing as "straight creation" of a parameter; the whole
shell model depends on dynamic scoping. Assignments *always* apply to
any parameter that is already in scope, the only way to change that is
by declaring the parameter with typeset/local/etc.
Furthermore, this specific instance is with reference to the earlier
documentation for ${NAME=WORD} et al. which says:
In the first form, if NAME is unset then set it to WORD; in the
second form, if NAME is unset or null then set it to WORD; and in
the third form, unconditionally set NAME to WORD.
There'd be no point in calling out the difference between set, unset,
and set but null parameters if they were being "created" in the way you
have interpreted it here.
So if the use of the word "create" here is actually confusing, it's
that word that should be changed; clarifying semantics of dynamic
scoping is something for a much larger context. Would it have led you
astray if instead the paragraph said "Assign as an array parameter ..." ?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Documentation on (A) Create array parameter
2017-02-22 19:58 ` Bart Schaefer
@ 2017-02-22 20:47 ` Sebastian Gniazdowski
0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Gniazdowski @ 2017-02-22 20:47 UTC (permalink / raw)
To: zsh-workers
On Wed, Feb 22, 2017, at 11:58 AM, Bart Schaefer wrote:
> On Feb 22, 3:40am, Sebastian Gniazdowski wrote:
> }
> } (A) completion and documentation suggest straight creation:
>
> There's no such thing as "straight creation" of a parameter; the whole
> shell model depends on dynamic scoping. Assignments *always* apply to
> any parameter that is already in scope, the only way to change that is
> by declaring the parameter with typeset/local/etc.
It's that if I have a new scope, and write "local param", I would say I
straight-create it. It will have the "oldpm" field set internally but
it's all like straight creation. If the scope is new. So I could expect
(A) will behave the same way. Use my current scope and create.
> scoping is something for a much larger context. Would it have led you
> astray if instead the paragraph said "Assign as an array parameter ..." ?
No that's fine.
--
Sebastian Gniazdowski
psprint2@fastmail.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-02-22 20:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-22 11:40 [PATCH] Documentation on (A) Create array parameter Sebastian Gniazdowski
2017-02-22 19:58 ` Bart Schaefer
2017-02-22 20:47 ` Sebastian Gniazdowski
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).