From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5876 invoked by alias); 26 Jun 2015 13:51:57 -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: 35613 Received: (qmail 27973 invoked from network); 26 Jun 2015 13:51:55 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f5-f794b6d000001495-cb-558d58f71d7b Date: Fri, 26 Jun 2015 14:51:48 +0100 From: Peter Stephenson To: Zsh Hackers' List Subject: PATCH: array slice Message-id: <20150626145148.32131e33@pwslap01u.europe.root.pri> In-reply-to: <20150625102923.1dc227ff@pwslap01u.europe.root.pri> 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> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrELMWRmVeSWpSXmKPExsVy+t/xy7rfI3pDDRb95bQ42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGRvvt7IWXBGo2PnmAVMD40eeLkYODgkBE4mlJwW6GDmBTDGJ C/fWs3UxcnEICSxllNh4dSYzhDODSWLtvNuMEM42RokVmztZQVpYBFQlTp4/DGazCRhKTN00 mxFkqoiAtkT7RzGQsLCAtMSnDyeZQWxeAXuJv7O3M4OUcAo4SDT/Z4EY+Y5J4syz7WBj+AX0 Ja7+/cQEcZG9xMwrZxghegUlfky+xwJiMwtoSWze1sQKYctLbF7zFmy+kIC6xI27u9knMArN QtIyC0nLLCQtCxiZVzGKppYmFxQnpeca6RUn5haX5qXrJefnbmKEhOzXHYxLj1kdYhTgYFTi 4Z3Z2hMqxJpYVlyZe4hRgoNZSYT3q09vqBBvSmJlVWpRfnxRaU5q8SFGaQ4WJXHembvehwgJ pCeWpGanphakFsFkmTg4pRoYEy8kea+sLNr08N+sIzZvY8Kn359Yy7Lz6a1Wu5Kc+wkmCetu VRUVGhSdP/l9Pds3zV9W/YULI56Vxc18FuBtHuv2//TG+PV8WrNDNyy/W3D0evbpX9V/nXN/ d38w+HBf++Rr4fDgfRPX6DV9yj6x9sz9RR+uPdC4YFV83ydYMDZ+h/+pEnmNXUosxRmJhlrM RcWJANExKkJVAgAA On Thu, 25 Jun 2015 10:29:23 +0100 Peter Stephenson wrote: > > That could also be extended to something like var[2,7]=(1 2) > > Extending assignments (at least to existing arrays) to handle array > slices would certainly be natural, yes. I hope m[o]st of the mechanism is > already present and just needs borrowing from addvars(). It looks like half closing your eyes, sticking your fingers in your ears, and copying what's there already does the trick. Nice to keep procedures consistent. (By the way, if I've been following what we've been doing, typeset foo[3]=blah is now guaranteed not to give you a "no match" error or bogus glob match, though typeset foo[3] isn't, but that doesn't matter as you can't change the attributes of an array element on its own.) pws diff --git a/Src/builtin.c b/Src/builtin.c index bc68545..3da1678 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2347,9 +2347,16 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), asg->is_array = 0; keeplocal = 0; on = pm->node.flags; + } else if (PM_TYPE(on) == PM_ARRAY && ASG_ARRAYP(asg)) { + if (!(pm = setaparam(pname, asg->value.array ? zlinklist2array(asg->value.array) : + mkarray(NULL)))) + return NULL; + asg->value.array = NULL; + keeplocal = 0; + on = pm->node.flags; } else { zerrnam(cname, - "%s: array elements must be scalar", pname); + "%s: inconsistent array element or slice assignment", pname); return NULL; } } diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst index 1548b81..5d69e5d 100644 --- a/Test/B02typeset.ztst +++ b/Test/B02typeset.ztst @@ -676,3 +676,18 @@ >array-local >yes >no + + array=(nothing to see here) + fn() { + typeset array=(one two three four five) + typeset array[2,4]=(umm er) + print ${#array} $array + typeset array[2,3]=() + print ${#array} $array + } + fn + print ${#array} $array +0:can update array slices in typeset +>4 one umm er five +>2 one five +>4 nothing to see here