Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; Define Chair Class
- (defclass chair ()
- ((color :accessor chair-color
- :initarg :color)
- (material :accessor chair-material
- :initarg :material)))
- (defparameter *example* (make-instance 'chair
- :color "Gray"
- :material "Steel"))
- (print *example*)
- ;; Output >> #<CHAIR {10037C8CD3}>
- (defmethod print-object ((obj chair) stream)
- (if (boundp '*print-method*)
- (print-unreadable-object (obj stream :type t)
- (format stream "Color: ~a~%" (chair-color obj))
- (format stream "Material: ~a" (chair-material obj)))
- (print "This is a cool chair")))
- ;; Output >> "This is a cool chair"
- (defun print-new-chair (color material)
- (let ((*print-method* t))
- (declare (special *print-method*))
- (print (make-instance 'chair :color color
- :material material))
- nil))
- (print-new-chair "Red" "Leather")
- ;; Output >> #<CHAIR Color: Red
- ;; Material: Leather>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement