I will conclude this chapter by discussing an alternative to message passing. Assume that we instead of
(send instance message actual-parameter ...)
want to activate a method via the following form:
(message instance actual-parameter ...)
I.e., we want to activate a method by calling a so-called generic procedure. Following this approach, we cannot syntactically distinguish an ordinary Lisp procedure call from an activation of a method in a class.
From the position of the message in the generic procedure call it is clear that message must designate a procedure object in Scheme. Besides this, a message must be an object that can be compared with a method selector using eqv? in the procedure self . This is not a problem because it makes sense to compare procedure objects with eqv? in Scheme [9].
It is easy to write a lambda expression in a pseudo notation for
the kind of messages that we need. Such a lambda expression is shown
in figure .
Figure: A pseudo lambda expression of a generic procedure.
There are several things to notice about this lambda expression:
We are now ready to express the pseudo formulation of the generic procedure in ``real Scheme''. Because of point 3, it is convenient to generate the selectors, instead of writing the needed lambda expressions repeatedly.
(define (make-selector) (letrec ((selector (lambda (instance . parameters) (apply send (append (list instance selector) parameters))))) selector))
The procedure make-selector
is the desired generator.
The purpose of letrec
is to bind a name to the needed procedure,
such that it can be referenced in its own definition.
The apply
form used on send
makes it possible for parameters to be
a parameter list of unknown length.
In order to use the described framework, we need explicitly to generate a selector for each of the entries in self . This has to be done external to the class, because the selectors play the dual role of generic procedures. Consequently, both the class definition and the selector generations need to be at the outer level.
The simulation of generic procedures, as described in this paper, is inspired by a similar technique described by by Adams and Rees in [2]. Generic procedures are used uniformly in the Common Lisp Object System (CLOS) [3,6].