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