From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3583 invoked by alias); 29 Apr 2015 10:57:35 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34993 Received: (qmail 2177 invoked from network); 29 Apr 2015 10:57:33 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=3cbgEp/1mBYntpV6CGLvfuABJJ6Vt2uRBfeo0o24bHk=; b=AWSI5sCu52gLiNNCgU93lzByv4XQxa0K8xrUoAf/QC6L0s0Zp3GRyPr1BMi0imqUEY URkFiV+tP0I0Y8fT4kAVvzz8KpbXdTNIeWjGa/AFh/HIGwIxT3ZPk9RATI1Tk9dd8TtW qxDYOe4BGGiHpO+1Zkgp2ufwdI0vda72tR1TvMEAlAyq+f3V+CzvnNDjjMBfzE/h4kjr dxd2SBR1NDmO1ZwEckbSaeXZPGJ6oq+br/4ZHaQrCpXBwGFq71gS8NKKrzGM9mgkYDiK Qu4Wn4Q3AbG7+UGiLQ4tpHfUpfAPrbOx8I7UsV0TX4eZ7Wxi5D1MzKdsR/MIyd0Bu17P Q9fw== MIME-Version: 1.0 X-Received: by 10.42.236.132 with SMTP id kk4mr2776242icb.46.1430305049941; Wed, 29 Apr 2015 03:57:29 -0700 (PDT) In-Reply-To: <20150429113602.374240c7@pwslap01u.europe.root.pri> References: <55407BBF.6020401@inlv.org> <20150429113602.374240c7@pwslap01u.europe.root.pri> Date: Wed, 29 Apr 2015 12:57:29 +0200 Message-ID: Subject: Re: [BUG] Can't mark unset variables as read-only From: Mikael Magnusson To: Peter Stephenson Cc: zsh workers Content-Type: text/plain; charset=UTF-8 On Wed, Apr 29, 2015 at 12:36 PM, Peter Stephenson wrote: > On Wed, 29 Apr 2015 08:35:43 +0200 > Martijn Dekker wrote: >> Unlike other shells, zsh can't mark an unset variable as read-only. > > Yes, the standard does indeed require that ability. As you can imagine, > something like this that completely breaks the normal programming model > of variables (a variable can't have state if it's unset because it > doesn't exist) is a nightmare to implement; however, it can at least be > limited to the POSIXBUILTINS option and maybe the cases using that are > simple enough that it mostly works. I'm sure there are any number of > strange edge cases, though. > > The output of "readonly -p" is still broken (doesn't show the unset > variables in a fashion that can be used for restoring the current state) > but it was anyway: > > typeset -ar '*' > *=() > > Er, no, I don't think that's going to work. > > So that can be fixed separately. I wanted the opposite thing the other day, sort of. I have a ZLE widget that looks at $WIDGET, and I wanted to reuse it by calling it from another widget, setting WIDGET to another value first. However, ZLE makes $WIDGET readonly special, and I couldn't find any combination of flags that let me make a non-readonly local WIDGET. Is that possible? % zle -N h; h() { local -h WIDGET; WIDGET=hi; echo $WIDGET }; bindkey '^[h' h % h: read-only variable: WIDGET % zle -N h; h() { local +r -h WIDGET; WIDGET=hi; echo $WIDGET }; bindkey '^[h' h % h:local: WIDGET: can't change type of a special parameter % zle -N h; h() { local WIDGET; WIDGET=hi; echo $WIDGET }; bindkey '^[h' h % WIDGET=h h: read-only variable: WIDGET compared to % () { readonly foo=3; () { local foo=5; echo $foo }; echo $foo } 5 3 -- Mikael Magnusson