From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9242 invoked from network); 12 Jun 2007 15:38:13 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.0 (2007-05-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=no version=3.2.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 12 Jun 2007 15:38:13 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 52341 invoked from network); 12 Jun 2007 15:38:07 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 12 Jun 2007 15:38:07 -0000 Received: (qmail 12732 invoked by alias); 12 Jun 2007 15:38:04 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23553 Received: (qmail 12723 invoked from network); 12 Jun 2007 15:38:03 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 12 Jun 2007 15:38:03 -0000 Received: (qmail 52008 invoked from network); 12 Jun 2007 15:38:03 -0000 Received: from cluster-c.mailcontrol.com (168.143.177.190) by a.mx.sunsite.dk with SMTP; 12 Jun 2007 15:37:59 -0000 Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly10c.srv.mailcontrol.com (MailControl) with ESMTP id l5CFbRlO008754 for ; Tue, 12 Jun 2007 16:37:54 +0100 Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Tue, 12 Jun 2007 16:36:25 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.8/8.13.4) with ESMTP id l5CFaPff030225 for ; Tue, 12 Jun 2007 16:36:25 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.13.8/8.13.8/Submit) with ESMTP id l5CFaPdf030222 for ; Tue, 12 Jun 2007 16:36:25 +0100 Message-Id: <200706121536.l5CFaPdf030222@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: retrieving array as number Date: Tue, 12 Jun 2007 16:36:25 +0100 From: Peter Stephenson X-OriginalArrivalTime: 12 Jun 2007 15:36:25.0322 (UTC) FILETIME=[6FAB44A0:01C7AD07] Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MailControl A-07-07-10 (www.mailcontrol.com) on 10.67.0.120 % array=(42) % print $(( array )) 0 This looks wrong to me. I've passed the result to matheval(), which is what we do with scalars, after sticking together with $IFS[0]. This makes things like array=(1 + 2) work, assuming $IFS[0] is whitespace. If it isn't, well, I tried. (There's no obvious reason why array=(1 2 3) IFS=+ eval 'print $(( array ))' shouldn't output 6, so it does.) Index: Src/params.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/params.c,v retrieving revision 1.129 diff -u -r1.129 params.c --- Src/params.c 29 May 2007 14:16:03 -0000 1.129 +++ Src/params.c 12 Jun 2007 15:30:34 -0000 @@ -1941,10 +1941,18 @@ mod_export zlong getintvalue(Value v) { - if (!v || v->isarr) + if (!v) return 0; if (v->inv) return v->start; + if (v->isarr) { + char **arr = getarrvalue(v); + if (arr) { + char *scal = sepjoin(arr, NULL, 1); + return mathevali(scal); + } else + return 0; + } if (PM_TYPE(v->pm->node.flags) == PM_INTEGER) return v->pm->gsu.i->getfn(v->pm); if (v->pm->node.flags & (PM_EFLOAT|PM_FFLOAT)) @@ -1959,10 +1967,18 @@ mnumber mn; mn.type = MN_INTEGER; - if (!v || v->isarr) { + + if (!v) { mn.u.l = 0; } else if (v->inv) { mn.u.l = v->start; + } else if (v->isarr) { + char **arr = getarrvalue(v); + if (arr) { + char *scal = sepjoin(arr, NULL, 1); + return matheval(scal); + } else + mn.u.l = 0; } else if (PM_TYPE(v->pm->node.flags) == PM_INTEGER) { mn.u.l = v->pm->gsu.i->getfn(v->pm); } else if (v->pm->node.flags & (PM_EFLOAT|PM_FFLOAT)) { -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview