Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [BUG] Can't mark unset variables as read-only
- X-seq: zsh-workers 34993
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- Subject: Re: [BUG] Can't mark unset variables as read-only
- Date: Wed, 29 Apr 2015 12:57:29 +0200
- Cc: zsh workers <zsh-workers@xxxxxxx>
- 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==
- In-reply-to: <20150429113602.374240c7@pwslap01u.europe.root.pri>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <55407BBF.6020401@inlv.org> <20150429113602.374240c7@pwslap01u.europe.root.pri>
On Wed, Apr 29, 2015 at 12:36 PM, Peter Stephenson
<p.stephenson@xxxxxxxxxxx> wrote:
> On Wed, 29 Apr 2015 08:35:43 +0200
> Martijn Dekker <martijn@xxxxxxxx> 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
% <press alt-h>
h: read-only variable: WIDGET
% zle -N h; h() { local +r -h WIDGET; WIDGET=hi; echo $WIDGET }; bindkey '^[h' h
% <press alt-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
% <press alt-h>WIDGET=h
h: read-only variable: WIDGET
compared to
% () { readonly foo=3; () { local foo=5; echo $foo }; echo $foo }
5
3
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author