diff --git a/mes.c b/mes.c index c2b83d46..31a86416 100644 --- a/mes.c +++ b/mes.c @@ -971,35 +971,60 @@ less_p (scm *a, scm *b) } scm * -minus (scm *a, scm *b) +minus (scm *x/*...*/) { + scm *a = car (x); assert (a->type == NUMBER); - assert (b->type == NUMBER); - return make_number (a->value - b->value); + int n = a->value; + x = cdr (x); + if (x == &scm_nil) + n = -n; + while (x != &scm_nil) + { + assert (x->car->type == NUMBER); + n -= x->car->value; + x = cdr (x); + } + return make_number (n); } scm * -plus (scm *a, scm *b) +plus (scm *x/*...*/) { - assert (a->type == NUMBER); - assert (b->type == NUMBER); - return make_number (a->value + b->value); + int n = 0; + while (x != &scm_nil) + { + assert (x->car->type == NUMBER); + n += x->car->value; + x = cdr (x); + } + return make_number (n); } scm * -divide (scm *a, scm *b) +divide (scm *x/*...*/) { - assert (a->type == NUMBER); - assert (b->type == NUMBER); - return make_number (a->value / b->value); + int n = 1; + while (x != &scm_nil) + { + assert (x->car->type == NUMBER); + n /= x->car->value; + x = cdr (x); + } + return make_number (n); } scm * -multiply (scm *a, scm *b) +multiply (scm *x/*...*/) { - assert (a->type == NUMBER); - assert (b->type == NUMBER); - return make_number (a->value * b->value); + int n = 1; + while (x != &scm_nil) + { + assert (x->car->type == NUMBER); + n *= x->car->value; + x = cdr (x); + } + return make_number (n); } scm * diff --git a/scm.mes b/scm.mes index edbc993b..73f28a8b 100755 --- a/scm.mes +++ b/scm.mes @@ -33,8 +33,6 @@ (#t (memq x (cdr lst))))) (define memv memq) -(define (+ x y) (- x (- 0 y))) - (define-macro (and x y) (cond (x y) (#t #f))) diff --git a/test.mes b/test.mes index 8e2ff1fb..5d004d64 100644 --- a/test.mes +++ b/test.mes @@ -238,6 +238,10 @@ (display (memq 'd '(a b c))) (newline) +(display "plus: ") +(display (+ 1 1 1 1)) +(newline) + (cond ((defined? 'loop2) (display "mes:values broken after loop2") (newline)) @@ -250,7 +254,7 @@ (display "call-with-values ==> 6: ") (display (call-with-values (lambda () (values 1 2 3)) - (lambda (a b c) (+ (+ a b) c)))) + (lambda (a b c) (+ a b c)))) (newline) (display "call-with-values ==> 1: ") (display ((lambda (x) x) (values 1 2 3)))