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

  1. Xref: sparky comp.lang.tcl:1904 comp.lang.perl:7071 comp.lang.scheme:2618
  2. Path: sparky!uunet!spool.mu.edu!umn.edu!csus.edu!ucdavis!toadflax!beard
  3. From: beard@toadflax.cs.ucdavis.edu (Patrick C. Beard)
  4. Newsgroups: comp.lang.tcl,comp.lang.perl,comp.lang.scheme
  5. Subject: Re: Closures, Object-Oriented Equivalence, New version of Perl and TCL
  6. Message-ID: <19236@ucdavis.ucdavis.edu>
  7. Date: 15 Nov 92 21:46:42 GMT
  8. References: <9211110521.AA01343@cs.columbia.edu>
  9. Sender: usenet@ucdavis.ucdavis.edu
  10. Followup-To: comp.lang.tcl
  11. Organization: Department of Computer Science, University of California, Davis
  12. Lines: 47
  13.  
  14. After thinking about the differences between objects and closures a little
  15. while, I agree that closures and objects can represent more or less the
  16. same concepts. Objects can be said to be closures plus syntactic sugar.
  17.  
  18. In my opinion, objects are closures with multiple entry points. In
  19. message passing object models for scheme, the fundamental problem to
  20. solve is how to look up a method by name. My current technique is to
  21. create nested "methods" or allow closures to be added to the object
  22. after the fact, and store these in association list inside the object.
  23. Then I convert a symbol to a closure to call using "assq" to look it
  24. up. Other methods I've seen amount to using a case statement, which seems
  25. rather difficult to maintain, in my opinion, and makes it impossible to
  26. add methods at runtime.
  27.  
  28. In C++, the compiler generates closures with multiple entry points.
  29. Essentially an object is an environment that is shared by a group of
  30. functions, very much like the way nested closures in Scheme share the
  31. same environment.  Unfortunately, the language doesn't support an
  32. automatic way to look up these nested closures by name and make them
  33. available to the world outside the object. Also, in Scheme, a
  34. "method/closure" that I've added to an object DOESN'T have access to
  35. the object's environment (can't access its local state).
  36.  
  37. This bit of work, plus inheritance, and other "bookkeeping" chores
  38. performed by an object-oriented language are what raises object
  39. oriented programming up to a new level of "convenience" above Scheme,
  40. if not necessarily a new level of "abstraction".
  41.  
  42. My other complaint about Scheme is that I am always paranoid about
  43. redefining some critical bit of built-in functionality. If I want to
  44. create a new number type, say an "interval" data type, and I want to
  45. be able to use + to add them, I have to redefine the global "+", being
  46. careful to safe its definition away inside my new definition of "+". I
  47. prefer C++'s way of "qualifying" names. The only names I really ever
  48. have to add to the global namespace in C++ are new class names.
  49.  
  50. Scheme should have multiple "top-level" environments. One that
  51. contains the built-in standard scheme bindings, that can't be changed,
  52. one for "extensions" provided by the local implementation, and one for
  53. the programmer to play in. It should be possible to "forget" bindings
  54. as well, and go back to a clean slate. Forth provides this ability.
  55.  
  56. Just a few ramblings from a former software engineer.
  57.  
  58. // Patrick C. Beard
  59. // Department of Computer Science, U. C. Davis
  60. // pcbeard@ucdavis.edu
  61.