t3x.org / sketchy / library / less.html
SketchyLISP
Reference
  Copyright (C) 2006
Nils M Holm

<

Conformance: R5RS

Purpose: Check whether two or more numbers are in ascending order. Return #t, if a<b<... and otherwise #f.

Arguments:
A - number
B... - numbers

Implementation:

(define (< a . b)
  (letrec

    ; Check whether A has fewer members than B
    ((shorter-list (lambda (a b)
      (cond ((null? a)
          (not (null? b)))
        ((null? b) #f)
        (#t (shorter-list (cdr a) (cdr b))))))

    (shorter (lambda (a b)
      (shorter-list (integer->list a)
        (integer->list b))))

    ; Check whether A has more members than B
    (longer (lambda (a b)
      (shorter b a)))

    ; Handle signs and lengths
    (less (lambda (a b)
      (cond ((negative? a)
        (cond ((non-negative? b) #t)
          ((shorter a b) #f)
          ((longer a b) #t)
          (#t (n< (abs b) (abs a)))))
      ((negative? b) #f)
      ((shorter a b) #t)
      ((longer a b) #f)
      (#t (n< (abs a) (abs b))))))

    (lt (lambda (a b)
      (cond ((eq? a #t) #t)
        ((less (integer a) (integer b)) b)
        (#t #t)))))

    (cond ((null? b)
        (bottom '(too few arguments to <)))
      (#t (neq? (reduce lt (cons a b) #f)
                #t)))))

Example:

(< -123 0) 
=> #t

See also:
digits, >, <=, >=, n<.