zsh-workers
 help / color / mirror / code / Atom feed
* Effects of readonly on associative arrays
@ 2008-05-11  6:24 Bart Schaefer
  0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 2008-05-11  6:24 UTC (permalink / raw)
  To: zsh-workers

This is probably my fault somehow, but:

% typeset -a arr
% typeset -r arr
% arr=(a 1)
zsh: read-only variable: arr
% arr[1]=a
zsh: read-only variable: arr
% typeset -A hash
% typeset -r hash
% hash=(a 1)
zsh: read-only variable: hash
% hash[a]=1
% typeset hash
hash=(a 1 )

I have a potential use for this quirk, but it seems like something not
really to be relied upon.

This is probably related to:

% typeset -r hash[a]
typeset: hash[a]: can't create readonly array elements

Furthermore, continuing the above example:

% typeset -a hash
% typeset hash
hash=()
% hash=(a 1)
zsh: readonly variable: hash

As it happens, what I really have use for is a variable whose values
can be changed but whose type cannot.  Here we have a situation where
I can effectively erase a read-only variable by changing its type --
which "works" for any non-special readonly variable.

Contrast this with what happens when the readonly variable is a
special parameter:

% userdirs[xxxx]=yyyy
zsh: read-only variable: xxxx
% typeset -a userdirs
zsh: userdirs: can't change type of a special parameter

Aside -- this is a bit strange:

% noglob typeset userdirs[xxxx]
zsh: read-only variable: xxxx


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

only message in thread, other threads:[~2008-05-11  6:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-11  6:24 Effects of readonly on associative arrays Bart Schaefer

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