zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: zsh-workers@sunsite.dk
Subject: Effects of readonly on associative arrays
Date: Sat, 10 May 2008 23:24:06 -0700	[thread overview]
Message-ID: <691a5d910805102324l3ae22814o2e1cd0e1c03cd896@mail.gmail.com> (raw)

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


                 reply	other threads:[~2008-05-11  6:24 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=691a5d910805102324l3ae22814o2e1cd0e1c03cd896@mail.gmail.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@sunsite.dk \
    /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).