- (let* ((s1 (string s1))
- (s2 (string s2))
- (end1 (or end1 (length s1)))
- (end2 (or end2 (length s2)))
- (len-1 (- end1 start1))
- (len-2 (- end2 start2)))
- (cond ((= len-1 0) nil)
- ((= len-2 0) 0)
- (t (dotimes (i len-2 nil)
- (when (= i len-1) ;; ran off the end of s1
- (return-from string> nil))
- (when (char> (char s1 (+ start1 i)) (char s2 (+ start2 i))) ;; found a difference
- (return-from string> (+ start1 i)))
- (when (char< (char s1 (+ start1 i)) (char s2 (+ start2 i))) ;; found a difference
- (return-from string> nil))
- (when (and (= i (1- len-2)) (> len-1 len-2)) ;; ran off the end of s2
- (return-from string> (+ start1 i 1))))))))
-
-;; TODO: string<=, string>=
-;; - mostly like string< / string>
-;; - if we run off the end of s1 and s2 at the same time, then it's =, so return len.
+ (compare-strings s1 s2 start1 end1 start2 end2
+ #'char= #'char< nil nil t))
+
+(defun string<= (s1 s2 &key (start1 0) end1 (start2 0) end2)
+ (compare-strings s1 s2 start1 end1 start2 end2
+ #'char= #'char> t t nil))
+
+(defun string>= (s1 s2 &key (start1 0) end1 (start2 0) end2)
+ (compare-strings s1 s2 start1 end1 start2 end2
+ #'char= #'char< t nil t))
+
+(defun string-lessp (s1 s2 &key (start1 0) end1 (start2 0) end2)
+ (compare-strings s1 s2 start1 end1 start2 end2
+ #'char-equal #'char-greaterp nil t nil))
+
+(defun string-greaterp (s1 s2 &key (start1 0) end1 (start2 0) end2)
+ (compare-strings s1 s2 start1 end1 start2 end2
+ #'char-equal #'char-lessp nil nil t))
+
+(defun string-not-greaterp (s1 s2 &key (start1 0) end1 (start2 0) end2)
+ (compare-strings s1 s2 start1 end1 start2 end2
+ #'char-equal #'char-greaterp t t nil))
+
+(defun string-not-lessp (s1 s2 &key (start1 0) end1 (start2 0) end2)
+ (compare-strings s1 s2 start1 end1 start2 end2
+ #'char-equal #'char-lessp t nil t))