Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!think.com!barmar From: barmar@think.com (Barry Margolin) Newsgroups: comp.object Subject: Re: Readability of Ada Message-ID: <1991Apr24.212237.29388@Think.COM> Date: 24 Apr 91 21:22:37 GMT References: <20245@alice.att.com> Sender: news@Think.COM Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 41 In article davis@barbes.ilog.fr (Harley Davis) writes: >I don't know about C++, but in several Lisp-based OO languages this is >cake. Here's a solution in EuLisp: ... > ;;; Printing out the radii of circles in a list. > > (defun print-radii (shape-list) > ;; Prints the radii of all the circles in SHAPE-LIST. > (mapc shape-list > (generic-lambda (shape) > method (((shape circle)) > (print (circle-radius shape)))))) Don't you need to define a default method for type shape? Or does EuLisp's GENERIC-LAMBDA automatically define a default method that does nothing? Also, I think you got the arguments to MAPC out of order (or is this a gratuitous incompatibility between EuLisp and Common Lisp?). >There you go. Nearly identical solutions will work in CommonLisp and >Le-Lisp, and probably every other Lisp with even the simplest object >oriented framework. Yes, OO programming in Smalltalk and many Lisp dialects generally doesn't have many of the limitations that it does in C++ and similar languages. The problem with C++ and friends is that the complete set of methods of a class must be declared in the class definition. In Lisp and Smalltalk, methods can be added to a class at any time, so the person implementing a generic function can decide which classes implement it. If OO programming is supposed to make incremental development and evolutionary programming easier, then the restrictions of C++ can be quite severe. There needs to be at least a way to specify a default method for classes that don't implement an operation, or a way to test class membership (Smalltalk and CLOS, naturally, have both, just to be complete). -- Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar