Paste number 18224: eqv

Index of paste annotations: 1

Paste number 18224: eqv
Pasted by: sneakin
When:3 years, 3 months ago
Share:Tweet this! | http://paste.lisp.org/+E28
Channel:#lisp
Paste contents:
Raw Source | XML | Display As
;;; The following equivalence checker was created by Nolan Eakins,
;;; http://nolan.eakins.net/ . This code can be treated as if it's
;;; public domain or public domain plus an attribution. This requires
;;; Gary King's Moputilities.

(defgeneric eqv (a b)
  (:documentation "This method is used to compare classes. Override it
to specialize it's testing for your classes. There's already a method
specialized for built in classes that uses EQUAL, cons cells, and any
standard object."))

(defmethod eqv (a b)
  (equal a b))

(defmethod eqv ((a cons) (b cons))
  (cond
    ((and a b)
     (and (eqv (first a) (first b))
	  (eqv (rest a) (rest b))))
    (t
     nil)))

(defun and-list (list)
  (if list
    (and (first list)
	 (and-list (rest list)))
    t))

(defmethod eqv ((a standard-object) (b standard-object))
  (when (eq (type-of a) (type-of b))
    (and-list
     (mapcar #'(lambda (slot)
		 (eqv (slot-value a slot)
		      (slot-value b slot)))
	     (mopu:slot-names (find-class (type-of a)))))))

Annotations for this paste:

Annotation number 1: Correction
Pasted by: sneakin
When:3 years, 3 months ago
Share:Tweet this! | http://paste.lisp.org/+E28#1
Paste contents:
Raw Source | Display As
This requires Gary King's Moptilities.

Colorize as:
Show Line Numbers
Index of paste annotations: 1

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.