Questions about CLOS, the CommonLispObjectSystem.
Questions that are very specific to CLOS are probably OffTopic on ThisWiki. Consider moving them to the AluWiki so we don't frighten the good WikiZens who ask themselves "AreLispersTakingOverThisWiki".
In many systems we can "send a message" that has not yet been defined, and then handle is in a proxy object. Is this possible?
Can we get a list of the methods that are available at runtime to call?
-
- ANSI Common Lisp defines the GenericFunction FIND-METHOD that takes a generic function, a list of method-qualifiers and a list of specializers as arguments and returns the method object that agrees on qualifiers and parameter specializers with these method-qualifiers and specializers (see section 7.7 of the CommonLispHyperSpec at http://www.lispworks.com/reference/HyperSpec/Body/f_find_m.htm).
-
- The CLOS MetaObjectProtocol described in the book TheArtOfTheMetaObjectProtocol and at http://www.elwoodcorp.com/alu/mop/ defines the generic function GENERIC-FUNCTION-METHODS. This reader for Generic Function Metaobjects returns the set of method metaobjects currently connected to a given generic function. The metaobject protocol is not part of the language standard; it is however supported by many implementations.
[From LispQuestions]
Does CLOS allow sending messages? For example in Smalltalk you can send a message that might not be defined to an object and the DoesNotUnderstand method is called.
-
- Short answer: yes.
-
- Long answer: Smalltalk is based on a message sending paradigm where you send a message to a single object. Messages are objects. When a message is sent to an object for a method it has not defined, then the message #doesNotUnderstand is sent to the original receiver with the original message as the single argument, and the receiver can inspect this message object and its arguments.
-
- The CommonLispObjectSystem is based on GenericFunctions where the method to be performed is determined by the types (and possibly the identities) of all parameters (see MultipleDispatch), so in CLOS there is no single receiver of the message. Generic functions are objects. If a generic function is called and no methods are applicable the generic function NO-APPLICABLE-METHOD is invoked instead with the generic function originally called and the parameters of this original call as parameters, and the results from that call are used as the results of the call to the original generic function (see section 7.6.6 of the CommonLispHyperSpec). NO-APPLICABLE-METHOD is not intended to be called by the user, but she may write methods for it. The default method signals an error.
Also see
HowObjectOrientedIsClos.
CategoryCommonLisp