home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / pop / 211 < prev    next >
Encoding:
Internet Message Format  |  1993-01-21  |  3.0 KB

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