;;; -*- Mode: Lisp -*-
;;;
;;; $Header: /home/gene/library/website/docsrc/amo/RCS/ordered.lisp,v 395.1 2008/04/20 17:25:45 gene Exp $
;;;
;;; Copyright (c) 2005 Gene Michael Stover.  All rights reserved.
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU Lesser General Public License as
;;; published by the Free Software Foundation; either version 2 of the
;;; License, or (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU Lesser General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public
;;; License along with this program; if not, write to the Free Software
;;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
;;; USA
;;;

(defpackage "ORDERED"
  (:use "COMMON-LISP")
  (:import-from "CYBERTIGGYR-TEST" "DEFTEST")
  (:export "XEQ"
	   "XGEQ"
	   "XGT"
	   "XLEQ"
	   "XLT"))
(in-package "ORDERED")

;;;
;;; Protocol for ORDERED
;;; Translated to Lisp from page 14 of Okasaki.
;;;

(defgeneric xeq (x y)
  (:documentation "True if & only if X & Y are equivalent."))
(defgeneric xgeq (x y))
(defgeneric xgt (x y))
(defgeneric xlt (x y)
  (:documentation "True if & only if X comes before Y."))
(defgeneric xleq (x y)
  (:documentation "True if & oly if X is XLT Y or X is XEQ Y."))

;;;
;;; Numeric Ordered
;;; Let's implement XEQ, XLT, & XLEQ for numbers so we can put
;;; numbers into our Binary Search Trees.
;;;

(defmethod xeq ((x number) (y number)) (= x y))
(defmethod xgeq ((x number) (y number)) (>= x y))
(defmethod xgt ((x number) (y number)) (> x y))
(defmethod xlt ((x number) (y number)) (< x y))
(defmethod xleq ((x number) (y number)) (<= x y))

(defmethod xeq ((x string) (y string)) (string-equal x y))
(defmethod xgeq ((x string) (y string)) (or (xeq x y) (xgt x y)))
(defmethod xgt ((x string) (y string)) (string-greaterp x y))
(defmethod xlt ((x string) (y string)) (string-lessp x y))
(defmethod xleq ((x string) (y string)) (or (xeq x y) (xlt x y)))

;;; --- end of file ---
