Skip to content

Instantly share code, notes, and snippets.

@MarkLavrynenko
Last active August 29, 2015 14:17
Show Gist options
  • Save MarkLavrynenko/f2e816aa1f30036f0680 to your computer and use it in GitHub Desktop.
Save MarkLavrynenko/f2e816aa1f30036f0680 to your computer and use it in GitHub Desktop.
DefClass basic
(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