I guess this would conflict with nameref-to-assoc, which currently does what I would expect. (Unless I'm missing something).
% typeset -n n=a
% echo ${n}
1 2
% echo ${(k)n}
a b
% typeset -A a=( a 1 b 2 )
Indeed. For reference, ksh;
$ typeset -A foo=([a]=1 [b]=2)
$ typeset -n bar=foo
$ echo ${!bar}
foo
$ echo "${!bar[@]}"
a b
Given Zsh's default unsubscripted-array expansion behavior, it seems like it would be hard to maintain the distinction between "what does this nameref point to" and "what are that thing's keys" if those semantics were combined in a single flag.
On Sun, Jul 19, 2026 at 11:53 PM Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Sun, Jul 19, 2026 at 10:24 AM Philippe Altherr
> <philippe.altherr@xxxxxxxxx> wrote:
> >
> > On Sun, Jul 19, 2026 at 6:36 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >>
> >> You're not noticing anything new, or rather the only thing new that you're noticing is that the (!) flag exists at all.
> >
> > I'm fully aware that the (!) flag is a part of named references, so not already present in any released version of Zsh.
>
> Well, yes. The (sorry, unstated) point was that everything you said
> about (k) is long-standing and (hopefully?) derivable from
> documentation or FAQ.
>
> However, if someone wants to convert those tables of differences into
> a format that could be included in either the FAQ or the "Other
> Differences" section of the zsh/ksh93 module documentation, it would
> probably be quite useful.
>
> >>> In ksh, the (!) flag can be used to list the keys of arrays and associative arrays. In that regard, it's closer to Zsh's (k) flag than Zsh's (!) flag
>
> The (k) flag was originally intended to mimic ksh's ! name prefix (due
> to ! colliding with history). The character "k" was chosen as a
> mnemonic for "like (k)sh". I suppose, rather than introduce (!), I
> could have extended (k) for the named reference behavior, to preserve
> that similarity. Could still try that if it seems a good idea.
I guess this would conflict with nameref-to-assoc, which currently
does what I would expect. (Unless I'm missing something).
% typeset -A a=( a 1 b 2 )
% typeset -n n=a
% echo ${n}
1 2
% echo ${(k)n}
a b
--
Mikael Magnusson
--