|
SketchyLISP Reference |
Copyright (C) 2007 Nils M Holm |
| <<[-] | [Index] | [<=]>> |
Conformance: R5RS Scheme
Purpose:
Check whether a seqeunce of numbers is in strict 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)
(else (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)
(else (n< (abs b) (abs a)))))
((negative? b) #f)
((shorter a b) #t)
((longer a b) #f)
(else (n< (abs a) (abs b))))))
(lt
(lambda (a b)
(cond ((eq? a #t) #t)
((less (integer a) (integer b)) b)
(else #t)))))
(cond ((null? b)
(bottom '(too few arguments to <)))
(else (neq? (fold-left lt a b) #t)))))
Example:
(< -123 0) => #t
See also:
digits,
>,
<=,
>=,
n<.
| <<[-] | [Index] | [<=]>> |