|
SketchyLISP Reference |
Copyright (C) 2007 Nils M Holm |
| <<[+] | [Index] | [<]>> |
Conformance: R5RS Scheme
Purpose: Subtract numbers. If only one argument is given, return its negative value.
Arguments:
A - number
B... - numbers (to be subtracted)
Implementation:
(define (- a . b)
(letrec
((idiff
(lambda (a b)
(cond ((negative? b)
(+ a (abs b))) ; B<0
((negative? a)
(+ a (negate b))) ; B>=0, A<0
((n< (abs a) (abs b))
(negate (n- (abs b) (abs a)))) ; A>=0, B>=0, A<B
(else (n- (abs a) (abs b)))))) ; A>=0, B>=0, A>=B
(i-
(lambda (a b)
(idiff (integer a) (integer b)))))
(cond ((null? b) (negate a))
(else (fold-left i- a b)))))
Example:
(- 5 7) => -2
See also:
digits,
+,
*,
quotient,
remainder,
n-.
| <<[+] | [Index] | [<]>> |