The ':answer' message selector adds or changes a method in the specified
class.
(setq myclass (send class :new '(var))) ; create MYCLASS with VAR (send myclass :answer :isnew '() ; set up initialization '((setq var nil) self)) (send myclass :answer :set-it '(value) ; create :SET-IT message '((setq var value))) (send myclass :answer :mine '() ; create :MINE message '((print "hi there"))) (setq my-obj (send myclass :new)) ; create MY-OBJ of MYCLASS (send my-obj :set-it 5) ; VAR is set to 5 (send my-obj :mine) ; prints "hi there"
Note: When you define a message in a
class, the message is only valid for
instances of the class or its
Message structure: The normal XLISP convention for a message is to have a valid symbol preceeded by a colon like :isnew or ':my-message'. However, it is possible to define a message that is a symbol without a colon, but this pollutes the global namespace and also makes the code less readable.
See also: