Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: f() { local -ar path=(/bin); };f gives an error
- X-seq: zsh-workers 42061
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: f() { local -ar path=(/bin); };f gives an error
- Date: Wed, 29 Nov 2017 22:12:08 +0000
- Cc: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=QrGTdHz0P3bu1UQxd8QylJDzjkAF84/Z2s4TcShuc/E=; b=n9A/IImA9nIqsZUNOGXVq1KIHRJTwMMEgM0A0465SBKNO++127B4tUfZmiH1yb3NsJ U0iWXl9e3xGmbhwT3RNG+lup361kePNRiM0Dj5d1NZiSbHHnx2/tMQzC1n7jYd9KWeLy gm1C9vHy0GwkdHqlZjhYFKi6BySyEXbJMQhv9rGWN5cB9D5Ih3FZ/yokvkGJTZj3Bl9f Cef4++APTTtnEEue+54EsWMF/rGYW4PPfG6I6omWRF2GY1V1FheaTfAKi2+7+XYt/0hC TWag8B/JVrhg9DfHc4XoHtcFC3nZYFSpOHYgPG5uVxOaeSgKV1kpGoCtjZwxqOM6r1cW dBMQ==
- In-reply-to: <CAH+w=7ZrxOwbY1iWCS5OcpNkoAOhQnYMCQX47+M3=yF9MNLgkg@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-followup-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20171126232101.GA8393@chaz.gmail.com> <7a5807b1-0c5e-8134-a651-83e8b3df4d82@gmx.com> <20171127201721.GA1897@chaz.gmail.com> <ff7d1972-7eec-2f0c-97bd-d1e958ae3cdd@gmx.com> <CAH+w=7ZrxOwbY1iWCS5OcpNkoAOhQnYMCQX47+M3=yF9MNLgkg@mail.gmail.com>
2017-11-27 13:34:05 -0800, Bart Schaefer:
> > On 11/27/2017 03:17 PM, Stephane Chazelas wrote:
> >>
> >> The issue here is that when you're trying to make $path (the
> >> special array variable tied to $PATH) readonly (with a value)
> >> locally in a function, that doesn't work.
>
> Something a little weird happens with order-of-operations for tied parameters:
>
> f() { local -ar path; PATH=foo; echo $path }
>
> Note there's no error there, $path is changed by the assignment to
> $PATH even though the array is read-only. The reverse also works; you
> have to make both parameters read-only to prevent changing either one
> by assignment to the other.
>
> f() { path=(/bin); local -r path PATH; ... } # achieves the desired effect
Wouldn't we want to propagate the "readonly" attribute to the
"tied" variable when the other one is made "readonly"?
There are other combinations that don't work so well like:
$ zsh -c 'typeset -Z3 -T A a; a=1; echo $A'
001
$ zsh -c 'typeset -T A a; typeset -Z3 A; a=(2 3); echo $a'
2 3
$ zsh -c 'typeset -T A a; typeset -Z3 A; A=1; echo $a'
1
-U is OK (often used with $PATH).
Would be worth going through all the combinations that one may
want to use and clarify which ones are legal which ones are not.
Having typeset return an error when two exclusive options are
used together (like typeset -iT (documented), typeset -ai (not))
would be helpful.
(why not allowing -i/-F/-Z... and most other scalar flags for
arrays and hashes btw?)
--
Stephane.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author