Skip to content

Instantly share code, notes, and snippets.

@commander-trashdin
Created August 24, 2024 11:44
Show Gist options
  • Save commander-trashdin/5188c90c6b0df698295e9b95e9772966 to your computer and use it in GitHub Desktop.
Save commander-trashdin/5188c90c6b0df698295e9b95e9772966 to your computer and use it in GitHub Desktop.
Fucking == in CLOS method combinations
(define-method-combination eql-combinator (&optional (order ':most-specific-last))
((around (:=) :order order)
(primary (eql-combinator) :order order :required t))
(if around
`(and ,@(mapcar (lambda (method)
`(call-method ,method))
around))
`(call-method ,(first primary))))
(defgeneric == (a b)
(:method-combination eql-combinator))
(defmethod == eql-combinator (a b)
(error "Equality undefined"))
(defclass a ()
((val :type integer
:accessor val
:initarg :val)))
(defclass b (a)
((name :type string
:accessor name
:initarg :name)))
(defclass c ()
((b :type b
:accessor b
:initarg :bl)))
(defclass d () ())
(defmethod == := ((x a) (y a))
(print "Checking a")
(= (val x) (val y)))
(defmethod == := ((x b) (y b))
(print "Checking b")
(string= (name x) (name y)))
(defmethod == := ((x c) (y c))
(print "Checking c")
(== (b x) (b y)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment