From: Jilles Tjoelker <jilles@stack.nl>
To: "ольга крыжановская" <olga.kryzhanovska@gmail.com>
Cc: dash@vger.kernel.org
Subject: Re: static vs. dynamic scoping
Date: Wed, 10 Nov 2010 22:01:30 +0100 [thread overview]
Message-ID: <20101110210130.GA17871@stack.nl> (raw)
In-Reply-To: <AANLkTi=CURDu8AVnAsT4esOBi5-xw8th5ix501jX0fRJ@mail.gmail.com>
On Wed, Nov 10, 2010 at 03:15:59PM +0100, ольга крыжановская wrote:
> Eric Blake wrote:
> > Or should dash switch entirely to static scoping (my gut feel is that
> > static scoping may be more efficient to implement, which fits in line
> > with dash's desire to be as lean as possible)?
> static scoping is much more efficient. Think about accessing a global
> variable in a deep function call stack, e.g. 20 functions deep. With
> dynamic scoping you have to look up the list of local variables for
> each function *first* before looking at the global variables. In my
> example this means 20 look ups. Each further function adds another
> look up.
> For static scoping you just look at the local variables of the
> *current* function and then look up the global ones. This is faster
> and much more efficient.
That's not how dash implements it, though. The local builtin saves the
value and attributes of the variable and they are restored upon return.
There is just one table of variables to search (two in older versions
and other ash versions, the additional one storing variable assignments
for regular builtins like IFS= read x; these were converted to the local
mechanism recently).
The real efficiency benefit of static scoping comes when disallowing
access to locals when the name is not known at compile time: at run
time, the names of the locals are not necessary.
--
Jilles Tjoelker
next prev parent reply other threads:[~2010-11-10 21:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-10 14:15 static vs. dynamic scoping ольга крыжановская
2010-11-10 21:01 ` Jilles Tjoelker [this message]
[not found] <4CD9C280.60007@redhat.com>
[not found] ` <4CDA6301.1010703@gmail.com>
2010-11-10 15:13 ` Eric Blake
2010-11-15 21:11 ` Cedric Blancher
2010-11-15 21:45 ` Eric Blake
-- strict thread matches above, loose matches on Subject: below --
2010-11-09 22:02 Eric Blake
2010-11-13 23:22 ` Harald van Dijk
2010-11-13 23:54 ` ольга крыжановская
2010-11-14 0:10 ` Harald van Dijk
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=20101110210130.GA17871@stack.nl \
--to=jilles@stack.nl \
--cc=dash@vger.kernel.org \
--cc=olga.kryzhanovska@gmail.com \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox