home *** CD-ROM | disk | FTP | other *** search
- From: sfk@otter.hpl.hp.com (Steve Knight)
- Date: Thu, 21 Jan 1993 18:13:33 GMT
- Subject: Re: lvars and standards (was: Re: List and Vector Syntax)
- Message-ID: <116670048@otter.hpl.hp.com>
- Organization: Hewlett-Packard Laboratories, Bristol, UK.
- Path: sparky!uunet!spool.mu.edu!sdd.hp.com!hpscit.sc.hp.com!hplextra!otter.hpl.hp.com!otter!sfk
- Newsgroups: comp.lang.pop
- References: <1993Jan7.154850.16982@syma.sussex.ac.uk>
- Lines: 58
-
- Brian writes:
- > Now I'm really confused. If B isn't lexically within A, then LA is *not*
- > visible. I'm thinking about an example like this. (Not beng a Pop programmer,
- > I'll have to use another language, sorry...) You've written some general
- > utility procedure, such as
-
- Umm, looking at my previous note I think I muddied the water by not
- properly distinguishing lexical scope and dynamic visibility. And
- since that is what this discussion is about I hereby smack myself on
- the wrist. (Ouch!)
-
- I'll have one more go at this. Brian is obviously correct in suggesting
- that LA is not in scope (by definition) but conflates this with
- visibility. The point I was trying to make is that a common interpretation
- of the dynamic environment for lexical bindings gives a meaning to LA
- within B's environment. To put this in a concrete framework, here's
- Brian's example.
-
- > ; a deliberately faulty program
- >
- > (define (nth num lst)
- > (if (= n 0)
- > (car lst)
- > (nth (- num 1) (cdr lst)) ))
- >
- > (define (last sequence)
- > (let ((size (length sequence)))
- > (nth size sequence) )) ; error
- >
- > Here you have forgotten that nth counts from zero, so the last element
- > is number SIZE-1, not number SIZE. You try running the program and it
- > blows up, attempting to apply CDR to an empty list. The error is caught
- > in NTH, but the error is really in LAST.
- >
- > Since NTH is not lexically within LAST, at the moment when the error
- > is caught the variable SIZE is not visible; it's in the wrong scope.
- > And that's the variable you have to examine to figure out what went
- > wrong.
-
- It is true that NTH is not lexically within LAST. However,
- dynamic visibility is not the same as lexical scope. When we inspect the
- dynamic bindings (if we use the normal meaning given by the
- denotational semantics) all the bindings are visible. My suggestion
- is that this interpretation of the binding environment makes the
- distinction between dynamic and lexical binding moot.
-
- The issue is that if you use lexical binding, the compiler doesn't have to
- generate a run-time structure to represent the dynamic bindings. Most
- compiler-writers exploit this performance enhancement and thereby
- undermine the ability to implement an interactive break loop. By contrast,
- the obvious implementation of dynamic binding generates a run-time
- structure that directly implements the dynamic environment.
-
- I hope this makes the general idea clear. You can get interactive access
- to lexical variables in a break loop -- but the implementation of this
- is much more awkward than for dynamic variables.
-
- Steve
-