Beruflich Dokumente
Kultur Dokumente
Contents
In statically typed languages
In Common Lisp Object System
Example
Common Lisp
Comparison to other languages
References
One of the early object-oriented programming extensions to Lisp is Flavors. It used the usual message sending paradigm influenced
by Smalltalk. The Flavors syntax to send a message is:
With New Flavors, it was decided the message should be a real function and the usual function call
ing syntax should be used:
(message object )
message now is a generic function, an object and function in its own right. Individual implementations of the message are called
methods.
The same idea was implemented in CommonLoops.[2] New Flavors and CommonLoops were the main influence for the Common
Lisp Object System.
Example
Common Lisp
Define a generic function with two parameters object-1 and object-2. The name of the generic function collide.
is
Methods belonging to the generic function are defined outside of classes. Here we define a method for the generic function collide
which is specialized for the classes asteroid (first parameter object-1) and spaceship (second parameter object-2). The parameters are
used as normal variables inside the method body
. There is no special namespace that has access to class slots.
Common Lisp can also retrieve individual methods from the generic function. FIND-METHOD finds the method from the generic
function collide specialized for the classesasteroid and spaceship.
References
1. The Common Lisp Object System: An Overview(http://www.dreamsongs.com/Files/ECOOP.pdf)
2. CommonLoops, Merging Lisp and Object-Oriented Programming(http://www2.parc.com/istl/groups/gir/papers/stefik-
commonloops-oopsla66.pdf)
Text is available under theCreative Commons Attribution-ShareAlike License ; additional terms may apply. By using this
site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of theWikimedia
Foundation, Inc., a non-profit organization.