One thing that helped me grok a little better lexical vs dynamic scope is to make a crude but perhaps useful comparison to C++:
lexical scope <--> tracing C++ method calls on non-virtual methods. You can tell trace the flow of control on paper beforehand; and know what's going to happen before running it, always.
dynamic scope <--> C++ virtual method invocation. You don't know until runtime which code (or variable value in the case of dynamic variables) are being talked about, because method dispatch (and variable access in the case of dynamic variables) depends on runtime current state.
I think dynamic variables (which are available in Common Lisp but not in most Schemes, if I understand right) and dynamic scoping are broader in application (a superset of) the facilities provided by C++ virtual methods, but it's the nearest thing in a language that you more likely familiar with.
Does that help?
Experts, feel free to improve on this comparison.
- Jason
On Mon, Sep 5, 2011 at 9:51 AM, Raffael Cavallaro raffaelcavallaro@mac.comwrote:
On Sep 5, 2011, at 10:02 AM, Steve Graham wrote:
Can someone help?
Marc's reply is, of course, succinct and correct.
If you want a fuller understanding of scope, I've found the wikipedia article to be relatively clear and to the point: http://en.wikipedia.org/wiki/Scope_(computer_science)
It covers both lexical (a.k.a. "static") scope, and dynamic scope, and gives examples.
hth
warmest regards,
Ralph
Raffael Cavallaro raffaelcavallaro@me.com
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list