From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13795 invoked from network); 15 Sep 2008 08:54:52 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 15 Sep 2008 08:54:52 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 48030 invoked from network); 15 Sep 2008 08:54:10 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 15 Sep 2008 08:54:10 -0000 Received: (qmail 8931 invoked by alias); 15 Sep 2008 08:54:04 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25671 Received: (qmail 8921 invoked from network); 15 Sep 2008 08:54:03 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 15 Sep 2008 08:54:03 -0000 Received: from cluster-g.mailcontrol.com (cluster-g.mailcontrol.com [208.87.233.190]) by bifrost.dotsrc.org (Postfix) with ESMTPS id DC8C880307AC for ; Mon, 15 Sep 2008 10:53:44 +0200 (CEST) Received: from cameurexb01.EUROPE.ROOT.PRI ([193.128.72.68]) by rly29g.srv.mailcontrol.com (MailControl) with ESMTP id m8F8rY5i027724 for ; Mon, 15 Sep 2008 09:53:39 +0100 Received: from news01 ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Mon, 15 Sep 2008 09:53:16 +0100 Date: Mon, 15 Sep 2008 09:53:11 +0100 From: Peter Stephenson To: "Zsh Hackers' List" Subject: Re: Should declare -p add a new declaration inside a function? Message-ID: <20080915095311.26f8a863@news01> In-Reply-To: <6cd6de210809131748y5dba13dbpef40377e95632206@mail.gmail.com> References: <6cd6de210809130752p4a5dc634v6144b0475e2cc569@mail.gmail.com> <20080913205540.4d80fcf6@pws-pc> <6cd6de210809131748y5dba13dbpef40377e95632206@mail.gmail.com> Organization: CSR X-Mailer: Claws Mail 3.5.0 (GTK+ 2.12.8; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 15 Sep 2008 08:53:16.0133 (UTC) FILETIME=[7E38B150:01C91710] X-Scanned-By: MailControl A-08-50-13 (www.mailcontrol.com) on 10.71.0.139 X-Virus-Scanned: ClamAV 0.92.1/8244/Mon Sep 15 10:40:46 2008 on bifrost X-Virus-Status: Clean On Sat, 13 Sep 2008 20:48:56 -0400 "Rocky Bernstein" wrote: > A couple things to consider. Right now if the variable is not declared, > declare -p returns 0. Should it be nonzero as is the case if you give a bad > option? Yes, I missed that the first time. > Is there a way to figure out or get a list of local variables versus > non-local variables versus global variables? By "local" I mean those that > were defined in the most recent scope and by "global" I mean those defined > outside of any function nesting, and by "non-local" I mean "not defined in > the immediate scope." You can use $parameters: fn() { local foo print ${(k)parameters[(R)*local*]} } ${(k)parameters[(R)^*local*]} (with extendedglob) gets you the global parameters. There's no way of telling which function level a variable is local at. Index: Src/builtin.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v retrieving revision 1.206 diff -u -r1.206 builtin.c --- Src/builtin.c 13 Sep 2008 19:59:14 -0000 1.206 +++ Src/builtin.c 15 Sep 2008 08:52:40 -0000 @@ -2479,8 +2479,10 @@ if (OPT_ISSET(ops,'p')) { if (hn) printparamnode(hn, printflags); - else + else { zwarnnam(name, "no such variable: %s", asg->name); + returnval = 1; + } continue; } if (!typeset_single(name, asg->name, (Param)hn, Index: Test/B02typeset.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/B02typeset.ztst,v retrieving revision 1.19 diff -u -r1.19 B02typeset.ztst --- Test/B02typeset.ztst 13 Sep 2008 19:59:14 -0000 1.19 +++ Test/B02typeset.ztst 15 Sep 2008 08:52:40 -0000 @@ -449,7 +449,7 @@ array=(foo bar) fn() { typeset -p array nonexistent; } fn -0:declare -p shouldn't create scoped values +1:declare -p shouldn't create scoped values >typeset -a array >array=(foo bar) ?fn:typeset: no such variable: nonexistent -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070