|
| From: | Per Bothner |
| Subject: | Re: translators and scoping rules (was: Re: language translator help) |
| Date: | Sun, 28 Apr 2002 08:26:45 -0700 |
| User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0rc1) Gecko/20020417 |
John W. Eaton wrote:
On 28-Apr-2002, Marius Vollmer <address@hidden> wrote: | "John W. Eaton" <address@hidden> writes:| | > How would you use eval to introduce a new local variable? | | You can't. If Octave needs this feature (but why?),Good question. I can't think of a really legitimate use, but it is possible to do this in Octave/Matlab, so I was wondering whether it could be emulated directly in Scheme.
Am I right in guesing that Octave uses dynamic scoping, rather than
lexical scoping? Certainly any local variable introduced by an eval
cannot be lexically scoped. However, it can be a dynamic or "fluid"
variable. So it would be consistent if all local variables were
fluid variables. (Common Lisp uses the term "special" variables.)
In a single-threaded environment it is easy implement dynamic/fluid
variables: When the variable is defined, you set the variable in
the global environment, but remember its previous value, if even.
When you exit the variable's scope, you restore the previous value.
It is harder to implement fluid variables in a multi-threaded
environment, but there are various ways you can do it. (Kawa does
support fluid bindings.)
--
--Per Bothner
address@hidden http://www.bothner.com/per/
| [Prev in Thread] | Current Thread | [Next in Thread] |