Created
December 1, 2019 15:13
-
-
Save lagagain/038aa9683189cb278db0ba179f229551 to your computer and use it in GitHub Desktop.
[Practice] Common Lisp: OOP method
This file contains hidden or 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 C1 nil | |
| ((a :type fixnum | |
| :reader get-a | |
| :writer set-a | |
| :initarg :a))) | |
| (defparameter *i1* (make-instance 'C1 :a 1)) | |
| (defparameter *i2* (make-instance 'C1 :a 2)) | |
| (defparameter *i3* (make-instance 'C1 :a 1)) | |
| (defmethod equal= ((a C1) &rest r) | |
| (if (not r) | |
| t | |
| (progn | |
| (loop for i in r do | |
| (unless (equal (get-a a) (get-a i)) | |
| (return-from equal= nil))) | |
| t))) | |
| (format t "~&~A~%" (get-a *i1*)) ;; => Output: 1 | |
| (format t "~&~A~%" (equal= *i1*)) ;; => Output: T | |
| (format t "~&~A~%" (equal= *i1* *i2*)) ;; => Output: Nil | |
| (format t "~&~A~%" (equal= *i1* *i3*)) ;; => Output: T |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment