zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: Obtaining the names of all local variables
Date: Sat, 27 Jun 2015 16:08:02 -0700	[thread overview]
Message-ID: <150627160802.ZM7033@torch.brasslantern.com> (raw)
In-Reply-To: <29780.1435441543@thecus.kiddle.eu>

On Jun 27, 11:45pm, Oliver Kiddle wrote:
} Subject: Re: Obtaining the names of all local variables
}
} Bart wrote:
} > This got me thinking, wouldn't it be helpful if zsh/parameter had an array
} > $locals that holds the names of all the local parameters?  Then you could
} > 
} >     needs_private_scope() { local -h $locals; ... }
} 
} I'm not sure I understand how that would achieve a private scope.

A few weeks ago someone asked for what amounts to lexical scoping of
local variables instead of dynamic scoping.  There's no way to achieve
that completely, but if you can hide all the variables that your
caller has made local, you get at least part of the way; you are then
guaranteed not to accidentally poke something into the caller's scope.

} -h is only applicable to special parameters.

Right, but if $locals contains a mix of non-special and special, you
(might) need the -h there.  The real point is to make the non-specials
local as well, which this ...

}   local -h ${(k)parameters[(R)*-special]}

... does not do, and besides that also makes the global specials local,
which is NOT the point.

} Or you could mark every parameter local.

That also hides the globals, which again is not the desired effect.

If there were a version of "typeset -g" that meant "expose the listed
top-level global variables, regardless of intervening dynamic scopes"
that would actually be a better starting point, but I think that's a
lot more difficult to achieve.  Maybe I'm wrong.


      reply	other threads:[~2015-06-27 23:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-25 15:46 Bart Schaefer
2015-06-27 21:45 ` Oliver Kiddle
2015-06-27 23:08   ` Bart Schaefer [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=150627160802.ZM7033@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /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).