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

n<

Conformance: SketchyLISP Core

Purpose: Check whether two numbers are in ascending order. Return #t, if a<b and otherwise #f. Both a and b must be natural numbers.

Arguments:
A - natural number
B - natural number

Model:

(define (n< a b)
  (letrec
    ; Check the ordering of two digits
    ; A - digit
    ; B - digit
    ; Result: A<B-> #T; #F
    ((d<
       (lambda (a b)
         (cond ((eq? a b) #f)
           ((eq? a 0d) #t)
           ((eq? b 0d) #f)
           (else (d< (pred a) (pred b))))))
     ; Check the inverse ordering of two digits
     ; A - digit
     ; B - digit
     ; Result: A>B-> #T; #F
     (d>
       (lambda (a b)
         (d< b a)))
     ; Check ordering.
     ; A - reverse list of digits
     ; B - reverse list of digits
     ; R - result: member of {#T,#F}
     (ltp
       (lambda (a b r)
         (cond ((and (null? a) (null? b)) r) ; all compared
           ((null? a) #t)        ; length[a] < length[b]
           ((null? b) #f)        ; length[a] > length[b]
           (else
             (ltp (cdr a) (cdr b)
               (cond ((d< (car a) (car b)) #t) ; default:
                 ((d> (car a) (car b)) #f) ; compare digits
                 (else r))))))))
    (ltp (reverse (integer->list a))
         (reverse (integer->list b))
         #f)))

Implementation:

; This function is a primitive function.

Example:

(n< 5 7) 
=> #t

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