home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / perl / 7033 < prev    next >
Encoding:
Internet Message Format  |  1992-11-22  |  2.3 KB

  1. Xref: sparky comp.lang.perl:7033 comp.lang.scheme:2605 comp.lang.tcl:1864
  2. Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!news.cs.columbia.edu!mail
  3. Newsgroups: comp.lang.perl,comp.lang.scheme,comp.lang.tcl
  4. Date: Wed, 18 Nov 92 00:09:50 EST
  5. From: thayer@cs.columbia.edu (Charles Thayer)
  6. Message-ID: <9211180509.AA04035@cs.columbia.edu>
  7. Subject: Re: Closures, Object-Oriented Equivalence, New version of Perl and TCL
  8. References: <9211110521.AA01343@cs.columbia.edu>
  9. Lines: 49
  10.  
  11. > For example, in Scheme, a 'define' saves the current environment and
  12. > leaves the ability to reach the enclosing (dynamic) environment:
  13.  
  14.    That's not quite right.  DEFINE does not save the current environment.
  15.    It only binds a value to a variable.
  16.  
  17. I was not refering to the scheme meaning of `environment'.  I meant
  18. the entire set of visible bindings.  In scheme the `environment' only
  19. holds the most immediate visible bindings.
  20.  
  21. I would also say that "define" creates a new binding in the current
  22. environment, as opposed to set! which changes the value bound to a
  23. variable in that variable's appropriate environment.
  24.    
  25.    When a closure is created with LAMBDA it effectively "remembers" the
  26.    current environment.  The environment doesn't always need to be saved,
  27.    though.  We only need to save the value of free variables within the
  28.    body of the LAMBDA expression.  If there are no free variables, we
  29.    don't need to keep any extra environment around.
  30.  
  31. [We do need to keep around a pointer to our parent environment, but
  32. we digress on implementation]
  33.  
  34. :)  Which brings up an interesting point in mit-scheme:
  35.  
  36. (begin
  37.   (define a "moo")
  38.   (define (foo) 
  39.     (display a)
  40.     (define a "bar")
  41.     )
  42.   (foo))
  43.  
  44. => Unassigned variable a
  45.  
  46. Astute PERL users will notice that there are similar holes in the 
  47. implementation of the exact same thing with respect to the main
  48. package  :)  which I find ironic.
  49.  
  50. /charles 
  51. PS.  It's also amusing to note that this is not a problem in languages
  52. with a lasier mode of evaluation including TCL and SIOD.  Mileage
  53. varies.
  54.  
  55. PPS. Disclaimer:  This is not meant to imply that this is a bug or
  56. a feature, just a fact to be aware of.
  57.  
  58. ==============================================================================
  59. Charles Thayer, Columbia University, Dept. CS, Tech-staff... my words only.
  60.