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

+

Conformance: R5RS Scheme

Purpose: Add numbers.

Arguments:
A... - numbers

Implementation:

(define (+ . a)
  (letrec
    ((_iplus
       (lambda (a b)
         (cond ((and (non-negative? a)
                     (non-negative? b))
             (n+ (abs a) (abs b)))
           ((and (non-negative? a)
                 (negative? b))
             (cond ((n> (abs a) (abs b))
                 (- a (abs b)))
               (else (negate (- (abs b) a)))))
           ((and (negative? a)
                 (non-negative? b))
             (cond ((n> (abs a) (abs b))
                 (negate (- (abs a) b)))
               (else (- b (abs a)))))
           ; both negative
           (else (negate (n+ (abs a) (abs b)))))))
     (i+
       (lambda (a b)
         (_iplus (integer a) (integer b)))))
    (fold-left i+ 0 a)))

Example:

(+ 5 7 9) 
=> 21

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