From 3bdebbdae839ed59ce4da43c7e6228a67d9cf6cf Mon Sep 17 00:00:00 2001 From: rayslava Date: Sat, 19 Jan 2013 23:27:18 +0400 Subject: [PATCH] Arithmetic operations on lists --- ecmalisp.lisp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ecmalisp.lisp b/ecmalisp.lisp index 7e3cda3..4d42329 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -1482,10 +1482,19 @@ (type-check (("x" "number" x) ("y" "number" y)) (concat "x" op "y"))) -(define-builtin + (x y) (num-op-num x "+" y)) -(define-builtin - (x y) (num-op-num x "-" y)) -(define-builtin * (x y) (num-op-num x "*" y)) -(define-builtin / (x y) (num-op-num x "/" y)) +(defmacro define-builtin-arithmetic (op) +`(define-raw-builtin ,op (&rest args) + (if args + (let ((res (ls-compile (car args)))) + (dolist (x (cdr args)) + (setq res (num-op-num res ,(symbol-name op) (ls-compile x)))) + res) + "0"))) + +(define-builtin-arithmetic +) +(define-builtin-arithmetic -) +(define-builtin-arithmetic *) +(define-builtin-arithmetic /) (define-builtin mod (x y) (num-op-num x "%" y)) -- 1.7.10.4