SketchyLISP Reference |
Copyright (C) 2006 Nils M Holm |
<<[n-] | [Index] | [n<=]>> |
Conformance: SketchyLISP Core
Purpose:
Check if two natural numbers are in ascending
order. Return
#t,
if
a<b
and otherwise
#f.
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) (#t (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] (#t (ltp (cdr a) (cdr b) (cond ((d< (car a) (car b)) #t) ; default: ((d> (car a) (car b)) #f) ; compare digits (#t 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>=,
=,
<.
<<[n-] | [Index] | [n<=]>> |