-
-
Save juan-reynoso/3303c079dcd4297667acc267f52192d6 to your computer and use it in GitHub Desktop.
Lisp Methods CLOS
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 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