tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
23
Task/Polymorphism/Common-Lisp/polymorphism.lisp
Normal file
23
Task/Polymorphism/Common-Lisp/polymorphism.lisp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
(defclass point ()
|
||||
((x :initarg :x :initform 0 :accessor x)
|
||||
(y :initarg :y :initform 0 :accessor y)))
|
||||
|
||||
(defclass circle (point)
|
||||
((radius :initarg :radius :initform 0 :accessor radius)))
|
||||
|
||||
(defgeneric shallow-copy (object))
|
||||
(defmethod shallow-copy ((p point))
|
||||
(make-instance 'point :x (x p) :y (y p)))
|
||||
(defmethod shallow-copy ((c circle))
|
||||
(make-instance 'circle :x (x c) :y (y c) :radius (radius c)))
|
||||
|
||||
(defgeneric print-shape (shape))
|
||||
(defmethod print-shape ((p point))
|
||||
(print 'point))
|
||||
(defmethod print-shape ((c circle))
|
||||
(print 'circle))
|
||||
|
||||
(let ((p (make-instance 'point :x 10))
|
||||
(c (make-instance 'circle :radius 5)))
|
||||
(print-shape p)
|
||||
(print-shape c))
|
||||
Loading…
Add table
Add a link
Reference in a new issue