Skip to content

Instantly share code, notes, and snippets.

@juan-reynoso
Last active June 14, 2022 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juan-reynoso/3303c079dcd4297667acc267f52192d6 to your computer and use it in GitHub Desktop.
Save juan-reynoso/3303c079dcd4297667acc267f52192d6 to your computer and use it in GitHub Desktop.
Lisp Methods CLOS
(defclass book ()
((name :accessor book-name
:initarg :book-name)))
(defclass door ()
((colour :accessor door-colour
:initarg :door-colour)))
(defclass window ()
((name :accessor window-name
:initarg :window-name)))
;; Creating Instances of Classes
(defparameter *book* (make-instance 'book :book-name "The Art of the Metaobject Protocol"))
(defparameter *door* (make-instance 'door :door-colour "white"))
(defparameter *window* (make-instance 'window :window-name "magic window"))
;;; Defining the method open-this of the book class
(defmethod open-this ((object book))
(format t "Open ... ~a book~%" (book-name object)))
;;; Defining the method close-this of the book class
(defmethod close-this ((object book))
(format t "~a book was closed ~%" (book-name object)))
;;; Defining the method open-this of the door class
(defmethod open-this ((object door))
(format t "Open ... the ~a door ~%" (door-colour object)))
;;; Defining the method close-this of the door class
(defmethod close-this ((object door))
(format t "The ~a door was closed~%" (door-colour object)))
;;; Defining the method open-this of the window class
(defmethod open-this ((object window))
(format t "Open ... the ~a ~%" (window-name object)))
;;; Defining the method close-this of the window class
(defmethod close-this ((object window))
(format t "The ~a was closed ~%" (window-name object)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment