Last active
August 29, 2015 14:17
-
-
Save MarkLavrynenko/f2e816aa1f30036f0680 to your computer and use it in GitHub Desktop.
DefClass basic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defclass tagged () ((tag :reader get-tag :writer set-tag :initform "Empty tag" :initarg :tag))) | |
(defclass 3d-point (tagged) | |
( | |
(x :reader get-x :writer set-x :initarg :x) | |
(y :reader get-y :writer set-y :initarg :y) | |
(z :reader get-z :writer set-z :initarg :z) | |
) | |
) | |
(setf point (make-instance '3d-point :x 1.0 :y 2.0 :z 3.0 :tag "Overwrite")) | |
(print (get-x point)) | |
(print (get-y point)) | |
(print (get-z point)) | |
(defmethod len((obj 3d-point)) | |
(expt (+ (expt (get-x obj) 2) (expt (get-y obj) 2) (expt (get-z obj) 2)) 0.5) | |
) | |
(print (len point)) | |
(print (get-tag point)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment