SketchyLISP Reference |
Copyright (C) 2006 Nils M Holm |
<<[*] | [Index] | [-]>> |
Conformance: R5RS
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))) (#t (negate (- (abs b) a))))) ((and (negative? a) (non-negative? b)) (cond ((n> (abs a) (abs b)) (negate (- (abs a) b))) (#t (- b (abs a))))) ; both negative (#t (negate (n+ (abs a) (abs b))))))) (i+ (lambda (a b) (_iplus (integer a) (integer b))))) (reduce i+ a 0)))
Example:
(+ 5 7 9) => 21
See also:
digits,
n+,
-,
quotient,
remainder,
*.
<<[*] | [Index] | [-]>> |