zsh-workers
 help / color / mirror / code / Atom feed
From: "Rocky Bernstein" <rocky.bernstein@gmail.com>
To: "Peter Stephenson" <pws@csr.com>
Cc: "Zsh Hackers' List" <zsh-workers@sunsite.dk>
Subject: Re: Should declare -p add a new declaration inside a function?
Date: Mon, 15 Sep 2008 11:58:28 -0400	[thread overview]
Message-ID: <6cd6de210809150858x54ebc2a2i9032ea6b5ccde922@mail.gmail.com> (raw)
In-Reply-To: <20080915095311.26f8a863@news01>

[-- Attachment #1: Type: text/plain, Size: 2942 bytes --]

On Mon, Sep 15, 2008 at 4:53 AM, Peter Stephenson <pws@csr.com> wrote:

> On Sat, 13 Sep 2008 20:48:56 -0400
> "Rocky Bernstein" <rocky.bernstein@gmail.com> 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.


Thanks. As many times in the past, this  helps a lot. I had tried to parse
error output in a regular expression but that's problematic and not as
simple.


>
>
> > 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*]}
> }


Interesting. This seems to show any variables defined local somewhere in the
call stack (not just the immediate one).



>
> ${(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.


There are a number of possibilities for tracking what variable goes with
what stack frame. Probably best to defer deciding on how exactly to deal
with.




>
>
> 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 <pws@csr.com>                  Software Engineer
> CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
> Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070
>

[-- Attachment #2: Type: text/html, Size: 4964 bytes --]

      reply	other threads:[~2008-09-15 15:59 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
2008-09-14  0:48   ` Rocky Bernstein
2008-09-15  8:53     ` Peter Stephenson
2008-09-15 15:58       ` Rocky Bernstein [this message]

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=6cd6de210809150858x54ebc2a2i9032ea6b5ccde922@mail.gmail.com \
    --to=rocky.bernstein@gmail.com \
    --cc=pws@csr.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).