home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / pop / 189 < prev    next >
Encoding:
Internet Message Format  |  1993-01-07  |  2.5 KB

  1. Path: sparky!uunet!spool.mu.edu!agate!anarres.CS.Berkeley.EDU!bh
  2. From: bh@anarres.CS.Berkeley.EDU (Brian Harvey)
  3. Newsgroups: comp.lang.pop
  4. Subject: Re: lvars and standards (was: Re: List and Vector Syntax)
  5. Date: 7 Jan 1993 23:12:38 GMT
  6. Organization: University of California, Berkeley
  7. Lines: 50
  8. Message-ID: <1iidd6INNa83@agate.berkeley.edu>
  9. References: <116670041@otter.hpl.hp.com> <C07Bop.DwH@cs.bham.ac.uk> <1993Jan7.154850.16982@syma.sussex.ac.uk>
  10. NNTP-Posting-Host: anarres.cs.berkeley.edu
  11.  
  12. ianr@syma.sussex.ac.uk (Ian Rogers) writes:
  13. >I have met noone who can provide a rational argument for dynamic
  14. >locals over lexical locals! [...]
  15. >lvars as default is a Good Thing, the One True Way, there Can Be No
  16. >Argument!!!!! :-)
  17.  
  18. I'm not a Pop programmer, but I've been teaching and programming using
  19. both Logo (dynamic scope) and Scheme (lexical scope) for many years.
  20. I can see good arguments on both sides.  I'm really happy to have both
  21. languages available to me.
  22.  
  23. There are two main things that I like about dynamic scope in Logo:
  24.  
  25. 1.  I find that debugging is easier for a beginner, who has no model of
  26. frames, bindings, and all that, in a dynamically scoped language.  When
  27. an error happens in Logo, the error handler just gives you a Logo prompt
  28. in the environment where the error happened -- and *all* the relevant
  29. variables in all the procedures higher up the stack are automatically
  30. available in the usual way.  By contrast, in lexically scoped Scheme, there
  31. is a special debugging language that has commands to shift focus from one
  32. environment to another.
  33.  
  34. 2.  It's easy to write control structures like WHILE in Logo because
  35. expressions are first-class.  You say
  36.  
  37.     to while :condition :action
  38.     if not RUN :CONDITION [stop]
  39.     RUN :ACTION
  40.     while :condition :action
  41.     end
  42.  
  43. The parts in capital letters evaluate an expression given as argument.
  44. Under dynamic scope, the variables of the procedure that invoked WHILE
  45. are available.  To do something similar in a lexically scoped language
  46. you have to explicitly create and pass a closure instead of just passing
  47. the expression:
  48.  
  49.     Logo:  while [:x > 0] [make "x :x-1]
  50.  
  51.     Scheme: (while (lambda () (> x 0))
  52.                (lambda () (set! x (- x 1))) )
  53.  
  54. It's the lambdas I'm objecting to.  (Yes, you can use macros so it looks
  55. nicer, but the Logo way is something a fifth-grader can understand.)
  56.  
  57.  
  58. These arguments aren't meant to say that dynamic scope is always the right
  59. thing.  Of course if you're trying to write a procedure that returns another
  60. procedure, lexical scope is very helpful.  I'm just reacting to the
  61. one-sidedness of the previous message.
  62.