zsh-workers
 help / color / mirror / code / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-workers@zsh.org
Subject: Re: static vs. dynamic scoping
Date: Wed, 10 Nov 2010 10:30:34 -0700	[thread overview]
Message-ID: <4CDAD6BA.1020902@redhat.com> (raw)
In-Reply-To: <101110092252.ZM6257@torch.brasslantern.com>

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

On 11/10/2010 10:22 AM, Bart Schaefer wrote:
> One additional thought on this ...
> 
> Zsh does have the "-g" option of "typeset" to allow one declare or
> to change the properties of a variable that is not in the scope of
> the current function.  However, "-g" doesn't really mean "global";
> it means only "the nearest dynamic scope where this variable is
> already declared" which is the global scope if the parameter has
> never been declared, but might even be the current scope if there
> has previously been a "local" delcaration of the variable.
> 
> Does ksh93 have any mechanism for explicitly declaring a variable to
> be global from inside a function scope?

I'm not that familiar with ksh93; you'd have to ask David Korn for
precise details.  But my understanding is that with static scoping,
every variable reference which was not explicitly declared local is
inherently global, because there are no other scopes to worry about.

That is (assuming ksh were to support local scoping with posix syntax
functions):

f () {
  a=1  # modify the global variable a
  typeset a;
  a=2  # modify the function-local a
}
a=0; f; echo $a # outputs 1

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

  reply	other threads:[~2010-11-10 17:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-09 22:08 Eric Blake
2010-11-10 11:10 ` Peter Stephenson
2010-11-10 16:50 ` Bart Schaefer
2010-11-10 17:28   ` Eric Blake
2010-11-10 17:43     ` Eric Blake
2011-05-29  6:38     ` Thorsten Glaser
2010-11-10 17:22 ` Bart Schaefer
2010-11-10 17:30   ` Eric Blake [this message]
2010-11-10 18:01     ` Bart Schaefer

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=4CDAD6BA.1020902@redhat.com \
    --to=eblake@redhat.com \
    --cc=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).