Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Effects of readonly on associative arrays
- X-seq: zsh-workers 24991
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Effects of readonly on associative arrays
- Date: Sat, 10 May 2008 23:24:06 -0700
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author