zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] [DOC] typeset -LRZul don't apply to (associative) arrays
Date: Wed, 24 May 2017 13:20:49 +0100	[thread overview]
Message-ID: <20170524122049.GB3861@chaz.gmail.com> (raw)

[-- 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:
 

                 reply	other threads:[~2017-05-24 12:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170524122049.GB3861@chaz.gmail.com \
    --to=stephane.chazelas@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).