X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fnumbers.lisp;h=18d679c3d7b61bc81cbb5038a108cc287911b623;hb=162bfa35d0b1a8a698dc813f6bc0874a043a225c;hp=a3105bb895738500c8e687b1bd9aeeaf8ade54c2;hpb=03fcd04876ff098055a8313d65fb1bef7bb57a5d;p=jscl.git diff --git a/src/numbers.lisp b/src/numbers.lisp index a3105bb..18d679c 100644 --- a/src/numbers.lisp +++ b/src/numbers.lisp @@ -26,9 +26,22 @@ ,init-sym)))) (define-variadic-op + 0) -(define-variadic-op - 0) (define-variadic-op * 1) -(define-variadic-op / 1) + +;; - and / work differently from the above macro. +;; If only one arg is given, it negates it or takes its reciprocal. +;; Otherwise all the other args are subtracted from or divided by it. +;; TODO: Use MACROLET when it exists +(defmacro define-sub-or-div (operator unary-form) + `(defun ,operator (x &rest args) + (cond + ((null args) ,unary-form) + (t (dolist (y args) + (setq x (,operator x y))) + x)))) + +(define-sub-or-div - (- x)) +(define-sub-or-div / (/ 1 x)) (defun 1+ (x) (+ x 1)) (defun 1- (x) (- x 1)) @@ -60,6 +73,7 @@ (defcomparison =) (defcomparison <) (defcomparison <=) +(defcomparison /=) (defconstant pi 3.141592653589793)