Mercurial > core / lisp/lib/obj/equiv.lisp
changeset 698: |
96958d3eb5b0 |
parent: |
8fe057887c17
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
1 ;;; obj/equiv.lisp --- Object Equivalence 3 ;; extended equivalence API for Lisp objects 7 ;; https://en.wikipedia.org/wiki/E-graph 9 ;; https://en.wikipedia.org/wiki/Equivalence_relation 11 ;; https://doc.rust-lang.org/std/cmp/index.html 13 ;; https://gitlab.com/fstamour/catchall/-/tree/master/egraph 15 ;; https://en.wikipedia.org/wiki/Disjoint-set_data_structure 17 ;; https://clojure.org/guides/equality 21 ;; A valid complaint of Common Lisp is the lack of an intuitive 22 ;; equality mechanism. We have the following symbols in the 23 ;; standard. If you want to write CL you need to have a very firm 27 = EQ EQL EQUAL EQUALP TREE-EQUAL 30 ;; EQUALP is the most flexible, but it is still explicitly conforming 31 ;; to the spec. It does handle STRUCTURE objects as one might expect, 32 ;; but it will not handle CLASSes. 34 ;; As a rule, don't mess with these (i.e. redefine them, or anything 35 ;; in the standard for that matter) and use them wherever 36 ;; possible. Anything that is testing equality between two lisp 37 ;; objects is very likely to boil down to one of the symbols above, 38 ;; and the compiler handles the rest. 40 ;; For simplicity, let us consider these symbols provided by the 41 ;; standard to be of the EQUALITY category. 43 ;; This package in essence provides a superset of this, called the 44 ;; EQUIVALENCE category. These functions are generic and designed to 45 ;; be implemented on user-defined objects with support for highly 46 ;; complex relationships, partial equality, and more. 48 ;; Here are some things to keep in mind for this potion of code: 50 ;; - I'm not as familiar with Clojure (which has equiv) and JVM 51 ;; semantics as much as I'd like to be on this topic. 53 ;; - I believe that Rust got it right for the most part. PartialEq and 54 ;; Eq are the two equality traits, with PartialOrd and Ord being the 55 ;; ordering traits which are a natural extension to equality. In 56 ;; turn the MAX and MIN functions build off of Ord (total 57 ;; order). The APIs that follow (order.lisp,limit.lisp) will be 58 ;; designed with these relationships in mind. 61 (in-package :obj/equiv) 63 (defgeneric equiv (a b)) 65 (defgeneric eqv (a b)) 67 (defgeneric nequiv (a b)) 69 (defgeneric neqv (a b)) 71 (defgeneric equals (a b &rest args))