История изменений
Исправление monk, (текущая версия) :
Collidable := Object clone do( collide := method(o, doMessage(o type asMessage) ) )
А что будешь делать, если надо несколько методов, а не только один?
(defmethod collide ((asteroid o1) (spaceship o2))
(print "asteroid collide with spaceship"))
(defmethod collide ((spaceship o1) (asteroid o2))
(print "spaceship collide with asteroid"))
(defmethod fire (o1 o2)
(print "it cannot fire"))
(defmethod fire ((spaceship o1) (asteroid o2))
(print "spaceship destroyed asteroid"))
(let ((asteroid (make-instance 'asteroid))
(spaceship (make-instance 'spaceship)))
(collide asteroid spaceship) ;; asteroid collide with spaceship
(collide spaceship asteroid) ;; spaceship collide with asteroid
(fire spaceship asteroid) ;; spaceship destroyed asteroid
(fire asteroid spaceship)) ;; it cannot fire
Исходная версия monk, :
[code]
Collidable := Object clone do( collide := method(o, doMessage(o type asMessage) ) )
А что будешь делать, если надо несколько методов, а не только один?
(defmethod collide ((asteroid o1) (spaceship o2))
(print "asteroid collide with spaceship"))
(defmethod collide ((spaceship o1) (asteroid o2))
(print "spaceship collide with asteroid"))
(defmethod fire (o1 o2)
(print "it cannot fire"))
(defmethod fire ((spaceship o1) (asteroid o2))
(print "spaceship destroyed asteroid"))
(let ((asteroid (make-instance 'asteroid))
(spaceship (make-instance 'spaceship)))
(collide asteroid spaceship) ;; asteroid collide with spaceship
(collide spaceship asteroid) ;; spaceship collide with asteroid
(fire spaceship asteroid) ;; spaceship destroyed asteroid
(fire asteroid spaceship)) ;; it cannot fire