Skip to content

Instantly share code, notes, and snippets.

@lagagain
Created December 1, 2019 15:13
Show Gist options
  • Select an option

  • Save lagagain/038aa9683189cb278db0ba179f229551 to your computer and use it in GitHub Desktop.

Select an option

Save lagagain/038aa9683189cb278db0ba179f229551 to your computer and use it in GitHub Desktop.
[Practice] Common Lisp: OOP method
(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