Commit 5bfba33e authored by Liam M. Healy's avatar Liam M. Healy
Browse files

Comparison functions with more than two arguments

The generic functions for comparison (<, >, etc.) have been renamed to
have an "i" at the end, e.g. "<i".  A regular function has been
defined for each that applies the generic function to each adjacent
pair to determine the truth of the set.
parent e7873448
;; Generic functions for generalized numbers
;; Liam Healy Tue Feb 9 1999 - 21:38
;; Time-stamp: <2011-09-09 22:58:09EDT generic.lisp>
;; Time-stamp: <2011-12-02 13:16:28EST generic.lisp>
;; Copyright 2011 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -315,34 +315,43 @@
(defgeneric numbcomp (x)
(:documentation "Function for number comparison. If this function is
defined for a generalized number and returns an object for which all
comparison functions such as g<, g>, etc. are defined,
comparison functions such as <, >, etc. are defined,
then all comparison functions will automatically be defined
for that object.")
(:method ((x number)) x))
(defgeneric >= (a b)
(defun multiarg-comparison (op args)
"Extend a comparison operator from two to any number of arguments."
(every op args (rest args)))
(defun >= (&rest args) (multiarg-comparison '>=i args))
(defgeneric >=i (a b)
(:documentation "Greater than or equal.")
(:method ((a number) (b number))
(cl:>= a b))
(:method (a b) (cl:>= (numbcomp a) (numbcomp b))))
(defgeneric > (a b)
(defun > (&rest args) (multiarg-comparison '>i args))
(defgeneric >i (a b)
(:documentation "Greater than")
(:method ((a number) (b number)) (cl:> a b))
(:method (a b) (cl:> (numbcomp a) (numbcomp b))))
(defgeneric <= (a b)
(defun <= (&rest args) (multiarg-comparison '<=i args))
(defgeneric <=i (a b)
(:documentation "Less than or equal.")
(:method ((a number) (b number))
(cl:<= a b))
(:method (a b) (cl:<= (numbcomp a) (numbcomp b))))
(defgeneric < (a b)
(defun < (&rest args) (multiarg-comparison '<i args))
(defgeneric <i (a b)
(:documentation "Less than.")
(:method ((a number) (b number)) (cl:< a b))
(:method (a b) (cl:< (numbcomp a) (numbcomp b))))
(defgeneric = (a b)
(defun = (&rest args) (multiarg-comparison '=i args))
(defgeneric =i (a b)
(:documentation "Numeric equal")
(:method ((a number) (b number))
(if (cl:= a b) a))
......
;; Mathematics on timepoints.
;; Liam Healy Fri Oct 12 2001 - 16:32
;; Time-stamp: <2011-01-15 17:17:43EST dtmath.lisp>
;; Time-stamp: <2011-12-02 12:30:19EST dtmath.lisp>
;; Copyright 2011 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -159,10 +159,10 @@
(list x (if (eq (scale x) (scale y)) y converted))))))
;;; define <, etc.
(defmethod < ((x timepoint) (y timepoint)) (timepoint-relation '< x y))
(defmethod > ((x timepoint) (y timepoint)) (timepoint-relation '> x y))
(defmethod <= ((x timepoint) (y timepoint)) (timepoint-relation '<= x y))
(defmethod >= ((x timepoint) (y timepoint)) (timepoint-relation '>= x y))
(defmethod <i ((x timepoint) (y timepoint)) (timepoint-relation '< x y))
(defmethod >i ((x timepoint) (y timepoint)) (timepoint-relation '> x y))
(defmethod <=i ((x timepoint) (y timepoint)) (timepoint-relation '<= x y))
(defmethod >=i ((x timepoint) (y timepoint)) (timepoint-relation '>= x y))
(defmethod = ((x timepoint) (y timepoint))
(defmethod =i ((x timepoint) (y timepoint))
(if (timepoint-relation '= x y) x))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment