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

-

Conformance: R5RS

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
        (#t (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))
      (#t (reduce i- (cons a b) #f)))))

Example:

(- 5 7) 
=> -2

See also:
digits, +, *, quotient, remainder, n-.