Wolfgang von Hansen <wvh@geodesy.inka.de> wrote:
+---------------
| > Dynamic binding was preferred for performance (?)
| > reasons in old systems
|
| Oh well, _you_ call it dynamic binding. To me it is simply preserving
| variables during recursion by putting them on a stack. :-) The idea of LISP
| was an A-list where the elements were inserted and removed at the beginning
| and bindings were retrieved by ASSOC. Of course performance may be a reason
| for dynamic binding, but it also is a simple approach to solve the problem.
+---------------
Actually, lexical scope gives *better* performance for access to variables,
since you can [if you do things right] compute the offsets back into the
environments at *compile* time -- you never need to search an A-list to
find the value of a variable. (An implementation may *choose* to search
the environment, but by using a little extra storage at closure-creation
time for a "display", it need not. A double index can be made to suffice.)
A dynamic A-list is ndeed simple to implement, but *understanding* programs
written with dynamic scope can be horribly complex! On the other hand, with
lexical scope, you can look at the static printed source text of a program
and *know* which binding is associated with each variable reference.
-Rob
-----
Rob Warnock, 7L-551 rpw3@sgi.com http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673 [New area code!]
2011 N. Shoreline Blvd. FAX: 650-933-4392
Mountain View, CA 94043 PP-ASEL-IA