zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: "Zsh Hackers' List" <zsh-workers@sunsite.dk>
Subject: Re: Should declare -p add a new declaration inside a function?
Date: Sat, 13 Sep 2008 20:55:40 +0100	[thread overview]
Message-ID: <20080913205540.4d80fcf6@pws-pc> (raw)
In-Reply-To: <6cd6de210809130752p4a5dc634v6144b0475e2cc569@mail.gmail.com>

On Sat, 13 Sep 2008 10:52:35 -0400
"Rocky Bernstein" <rocky.bernstein@gmail.com> wrote:
> It appears that using "declare" or "typeset" with the -p (print) flag will
> add a new declaration inside a function. Is this really desirable? It seems
> to reduce the usefulness of -p.

That sure as heck looks like a bug to me.  It shouldn't ever create
anything, even if the variable doesn't exist; it's purely for
information.  I don't think "declare -p" has had much love and
attention; it doesn't look like it's ever worked with arguments
other than patterns (with -m).

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.205
diff -u -r1.205 builtin.c
--- Src/builtin.c	11 Sep 2008 17:14:39 -0000	1.205
+++ Src/builtin.c	13 Sep 2008 19:49:33 -0000
@@ -2473,10 +2473,17 @@
 
     /* Take arguments literally.  Don't glob */
     while ((asg = getasg(*argv++))) {
-	if (!typeset_single(name, asg->name,
-			    (Param) (paramtab == realparamtab ?
-				     gethashnode2(paramtab, asg->name) :
-				     paramtab->getnode(paramtab, asg->name)),
+	HashNode hn = (paramtab == realparamtab ?
+		       gethashnode2(paramtab, asg->name) :
+		       paramtab->getnode(paramtab, asg->name));
+	if (OPT_ISSET(ops,'p')) {
+	    if (hn)
+		printparamnode(hn, printflags);
+	    else
+		zwarnnam(name, "no such variable: %s", asg->name);
+	    continue;
+	}
+	if (!typeset_single(name, asg->name, (Param)hn,
 			    func, on, off, roff, asg->value, NULL,
 			    ops, 0))
 	    returnval = 1;
Index: Test/B02typeset.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/B02typeset.ztst,v
retrieving revision 1.18
diff -u -r1.18 B02typeset.ztst
--- Test/B02typeset.ztst	16 Dec 2007 14:05:16 -0000	1.18
+++ Test/B02typeset.ztst	13 Sep 2008 19:49:33 -0000
@@ -444,3 +444,12 @@
 0:Lower case conversion, does not apply to values used internally
 >lower
 >value of $lower
+
+ typeset -a array
+ array=(foo bar)
+ fn() { typeset -p array nonexistent; }
+ fn
+0:declare -p shouldn't create scoped values
+>typeset -a array
+>array=(foo bar)
+?fn:typeset: no such variable: nonexistent


-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2008-09-13 19:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-13 14:52 Rocky Bernstein
2008-09-13 19:55 ` Peter Stephenson [this message]
2008-09-14  0:48   ` Rocky Bernstein
2008-09-15  8:53     ` Peter Stephenson
2008-09-15 15:58       ` Rocky Bernstein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080913205540.4d80fcf6@pws-pc \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).