- ; a
custom printing method for the
objects of
class person CL-USER > (
defmethod print-object ((p person) stream) (print-unreadable-object (p
stream :type...
- other-object)) (
defmethod do-something ((object engine) (other-object integer)) (format t "starting
engine ~s ~s times~%"
object other-object)) (
defmethod do-something...
- (Common Lisp
example shown): (
defmethod collide-with ((x asteroid) (y asteroid)) ;; deal with
asteroid hitting asteroid ) (
defmethod collide-with ((x asteroid)...
- ;;
Example of a
calculated property getter (this is
simply a method) (
defmethod student-age ((self student)) (- (get-universal-time) (student-birthdate...
- and
generic functions. CLOS
provides macros to
define those: defclass,
defmethod, and defgeneric.
Instances are
created with the
method make-instance....
- change. ;;; (
defmethod initialize-instance :after ((c circle) &key radius) (setf (radius c) radius)) ;; via the setf
method below (
defmethod (setf radius)...
-
Common Lisp
using the
Common Lisp
Object System: (defclass foo () ()) (
defmethod print-****o ((f foo)) (format T "****o from ~S~%" f)) ;; Normal, without...
- (a b)) (
defmethod add ((a number) (b number)) (+ a b)) (
defmethod add ((a vector) (b number)) (map 'vector (lambda (n) (+ n b)) a)) (
defmethod add ((a...
- when (make-sound x) is called, if x is an
instance of the dog class. (
defmethod make-sound ((obj dog)) (format t "woof!~%")) ;;
allow (make-sound nil)...
- is the
method qualifier for the
method combination of the same name. (
defmethod object-width + ((object button)) (* 10 (length (slot-value
object 'text))))...