From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18212 invoked by alias); 27 Jun 2015 19:42:08 -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: 35635 Received: (qmail 16631 invoked from network); 27 Jun 2015 19:42:06 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 X-Originating-IP: [80.3.228.158] X-Spam: 0 X-Authority: v=2.1 cv=dtgmcAU4 c=1 sm=1 tr=0 a=P+FLVI8RzFchTbbqTxIDRw==:117 a=P+FLVI8RzFchTbbqTxIDRw==:17 a=NLZqzBF-AAAA:8 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=xqWbkBAlgNji0IqDN3MA:9 a=CjuIK1q_8ugA:10 Date: Sat, 27 Jun 2015 20:42:02 +0100 From: Peter Stephenson To: "Zsh Hackers' List" Subject: Re: PATCH: array slice Message-ID: <20150627204202.4623aa2e@ntlworld.com> In-Reply-To: <150626160745.ZM2566@torch.brasslantern.com> References: <5578996E.3080700@thequod.de> <150610191427.ZM30841@torch.brasslantern.com> <5579C247.1060800@thequod.de> <150611183639.ZM32247@torch.brasslantern.com> <20150612094237.338f79d5@pwslap01u.europe.root.pri> <20150619123930.2688d9e3@pwslap01u.europe.root.pri> <7337.1434735386@thecus.kiddle.eu> <20150625102923.1dc227ff@pwslap01u.europe.root.pri> <20150626145148.32131e33@pwslap01u.europe.root.pri> <150626160745.ZM2566@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 26 Jun 2015 16:07:45 -0700 Bart Schaefer wrote: > This error message looks odd: > > torch% typeset y[2,4]=(x) > typeset: y[2,4]: can't create local array elements > > I guess that isn't new, but to refer to "local" at top-level prompt is > funny. "(on & PM_LOCAL)" is evidently true even though the typeset is > not within function scope. Amusingly it works to simply force the > variable to be global: > > torch% typeset -g y[2,4]=(x) > torch% typeset -p y > typeset -a y > y=('' x) > > And an array is always created for this, even without the parens: > > torch% typeset -g z[2,4]=y > torch% typeset -p z > typeset -a z > z=('' y) OK, so it does work if it *would* create a local if it could but is *actually* going to create a global in practice. This probably isn't all that useful in practice --- in the second case, you haven't even told it you want an array. It would take more work to fix this so it does something sensible if the variable would be local --- we get into a mess later, which is what I think the error is for. I don't quite understand why but I've lost interest / the will to live; there are too many combinations. pws --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2325,7 +2325,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), zerrnam(cname, "%s: can't create readonly array elements", pname); return NULL; - } else if (on & PM_LOCAL) { + } else if ((on & PM_LOCAL) && locallevel) { *subscript = 0; pm = (Param) (paramtab == realparamtab ? gethashnode2(paramtab, pname) :