From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9972 invoked by alias); 29 Nov 2017 22:12:17 -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: List-Unsubscribe: X-Seq: 42061 Received: (qmail 1031 invoked by uid 1010); 29 Nov 2017 22:12:17 -0000 X-Qmail-Scanner-Diagnostics: from mail-wr0-f179.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.128.179):SA:0(-1.9/5.0):. Processed in 1.250409 secs); 29 Nov 2017 22:12:17 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: stephane.chazelas@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state: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=EE1uALLMux9hhtC/oZHRCHigj1ZACucvXPO3zvGKX9CUAZuTeCx3HbfJnc21nIK1mC HXoT9bav6jRGrPW9YRUZrSfnFwoXskdf2+md3i+uc6DdMwi4xwke6pYADTRYOy5tz+9d KYdWI0OFRRZYME+HL3aUHKfujkxhMcsIizuG8dEEME3fjkE1FvhRD90wvYT1OCSA6IZC oRHLVk9541OFph3WGdbMlNE6jznTD4qA7mdbbp7l6JJ80s3ZlSMT9S010LplF/1QhbJ7 RGG2d0QlYe4DdifRg96MSL/hriB0N0VdNOp2ELJM4UtHutzdcE0M8kCI18VTnmhQ0gUs di6w== X-Gm-Message-State: AJaThX7bJg2SVBMC277SrWGRdjrrjYMYf/LUV4j0UcYZD74xOPPRLRZY I5LyScr05P1C3KR5eKylNGMpbA== X-Google-Smtp-Source: AGs4zMZGPihLLUKBtR8/qSQDLPe1pCjOAhMCBIoeGh3a+hlx2n7tuKPfghWd5+L084vu8ZeLiJJMiQ== X-Received: by 10.223.148.166 with SMTP id 35mr227418wrr.245.1511993531040; Wed, 29 Nov 2017 14:12:11 -0800 (PST) Date: Wed, 29 Nov 2017 22:12:08 +0000 From: Stephane Chazelas To: Bart Schaefer Cc: "zsh-workers@zsh.org" Subject: Re: f() { local -ar path=(/bin); };f gives an error Message-ID: <20171129221208.GA1984@chaz.gmail.com> Mail-Followup-To: Bart Schaefer , "zsh-workers@zsh.org" References: <20171126232101.GA8393@chaz.gmail.com> <7a5807b1-0c5e-8134-a651-83e8b3df4d82@gmx.com> <20171127201721.GA1897@chaz.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) 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.