zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] [DOC] typeset -LRZul don't apply to (associative) arrays
@ 2017-05-24 12:20 Stephane Chazelas
  0 siblings, 0 replies; only message in thread
From: Stephane Chazelas @ 2017-05-24 12:20 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 1059 bytes --]

typeset -u (for uppercase) and others like -LRZul don't apply to
(associative) arrays:

$ typeset -au a
$ a=(a)
$ echo $a
a

Just as well IMO as it would cause confusion with -U, or worse
for the keys of associative arrays. People can (and probably
should always instead of using those ksh-style flags) use
parameter-expansion-flags instead (${(U)array}...).

Other option is to go the ksh93 way:

$ ksh93 -c 'typeset -a -u -R3  a; a=(a b); printf "<%s>\n" "${a[@]}"'
<  A>
<  B>
$ ksh93 -c 'typeset -A -u a; a=([a]=x [A]=y); for k in "${!a[@]}"; do printf "%s => %s\n" "$k" "${a[$k]}"; done'
A => Y
a => X

(for associative arrays, only the values are transformed, though
for elements whose values are arrays, that doesn't apply to the
values of those arrays:
$ ksh93 -c 'typeset -A -u a; a=([a]=x [b]=(n m)); echo "${a[a]}" "${a[b][0]}"'
X n
).


Doc patch attached for the current situation. I'd say it's
probably not worth mentioning that in the case of arrays tied to
scalars (typeset -T), only the expansion of the scalar one is
affected.

-- 
Stephane

[-- Attachment #2: typeset-doc.diff --]
[-- Type: text/x-diff, Size: 646 bytes --]

diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 81687c7..0e26da3 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -2012,7 +2012,8 @@ enditem()
 Attribute flags that transform the final value (tt(-L), tt(-R), tt(-Z),
 tt(-l), tt(-u)) are only applied to the expanded value at the point
 of a parameter expansion expression using `tt($)'.  They are not applied
-when a parameter is retrieved internally by the shell for any purpose. 
+when a parameter is retrieved internally by the shell for any purpose.
+They have no effect on array or associative array parameters.
 
 The following attribute flags may be specified:
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-05-24 12:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-24 12:20 [PATCH] [DOC] typeset -LRZul don't apply to (associative) arrays Stephane Chazelas

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).