Path: utzoo!attcan!uunet!cs.utexas.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!jato!jade!brian From: brian@jade.jpl.nasa.gov (Brian of ASTD-CP) Newsgroups: comp.lang.scheme Subject: OOP in Scheme (addendum) Message-ID: <1406@jato.Jpl.Nasa.Gov> Date: 3 Jul 89 08:16:05 GMT References: <1404@jato.Jpl.Nasa.Gov> Sender: news@jato.Jpl.Nasa.Gov Reply-To: brian@jade.Jpl.Nasa.Gov (Brian of ASTD-CP) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 49 ; methods.scm (ADDENDUM) ; ; =============================================================== ; Brian Beckman | brian@topaz.jpl.nasa.gov ; Mail Stop 510-202 | (818) 397-9207 ; Jet Propulsion Laboratory | ; Pasadena, CA 91109 | 30 June 1989 ; =============================================================== ; There are two ways to invoke a method in an object. The ; first is to send the object a message, getting back a procedure. ; This procedure can then be invoked at will on an appropriate ; set of arguments. Such an idiom usually results in expressions ; like the following: ; ; ((foo 'do-it) arg1 arg2) ; ; This is fairly readable and a fine idiom, but it has its ; limitations. Suppose that this expression were to result in ; another object, to which we should like to send the message ; 'baz with the arguments 'rat and 'ter. Then we should write ; the following: ; ; ((((foo 'do-it) arg1 arg2) 'baz) 'rat 'ter) ; ; The number of leading parentheses is a problem. It is easy ; to devise nested message passing expressions that are ; much more difficult to write than to devise, merely because of ; the number of leading parentheses that must be presaged. Lisp ; already has a problem with closing parentheses; we don't want ; to compound the felony in this package by introducing a ; corresponding problem with opening parentheses. ; ; We need a ``send'' routine that does little more than reduce ; the need for leading parenthese. This is, admittedly, merely ; a syntactic issue. Consider the following, which is the second ; way to send a message to an object: (define (send object msg . args) (apply (object msg) args)) ; The earlier example message passing expressions can now be ; much more easly written much more nicely, as follows: ; ; (send object 'msg arg1 arg2) ; ; and ; ; (send (send object 'msg arg1 arg2) 'baz 'rat 'ter)