From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17490 invoked from network); 11 May 2008 06:24:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 11 May 2008 06:24:23 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 40810 invoked from network); 11 May 2008 06:24:16 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 11 May 2008 06:24:16 -0000 Received: (qmail 8411 invoked by alias); 11 May 2008 06:24:12 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24991 Received: (qmail 8392 invoked from network); 11 May 2008 06:24:11 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 11 May 2008 06:24:11 -0000 Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.237]) by bifrost.dotsrc.org (Postfix) with ESMTP id 7685780ED172 for ; Sun, 11 May 2008 08:24:07 +0200 (CEST) Received: by rv-out-0506.google.com with SMTP id g37so1883310rvb.21 for ; Sat, 10 May 2008 23:24:06 -0700 (PDT) Received: by 10.141.116.16 with SMTP id t16mr3046605rvm.60.1210487046610; Sat, 10 May 2008 23:24:06 -0700 (PDT) Received: by 10.141.48.18 with HTTP; Sat, 10 May 2008 23:24:06 -0700 (PDT) Message-ID: <691a5d910805102324l3ae22814o2e1cd0e1c03cd896@mail.gmail.com> Date: Sat, 10 May 2008 23:24:06 -0700 From: "Bart Schaefer" To: zsh-workers@sunsite.dk Subject: Effects of readonly on associative arrays MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: ClamAV 0.91.2/7083/Sat May 10 17:55:11 2008 on bifrost X-Virus-Status: Clean 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