From: David Vázquez Date: Sun, 20 Jan 2013 17:39:37 +0000 (+0000) Subject: Fix n-arity comparisons X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=c90b70190d55a8eb5e57db4548577217fb1ee4d8;p=jscl.git Fix n-arity comparisons --- diff --git a/ecmalisp.lisp b/ecmalisp.lisp index d485335..69425df 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -1605,16 +1605,23 @@ (define-builtin mod (x y) (num-op-num x "%" y)) + +(defun comparison-conjuntion (vars op) + (cond + ((null (cdr vars)) + "true") + ((null (cddr vars)) + (concat (car vars) op (cadr vars))) + (t + (concat (car vars) op (cadr vars) + " && " + (comparison-conjuntion (cdr vars) op))))) + (defmacro define-builtin-comparison (op sym) - `(define-raw-builtin ,op (&rest args) - (js!bool - (let ((x (car args)) - (res "true")) - (dolist (y (cdr args)) - (setq res (concat "(" - (ls-compile x) " " ,sym " " (ls-compile y) ")" " && " res)) - (setq x y)) - res)))) + `(define-raw-builtin ,op (x &rest args) + (let ((args (cons x args))) + (variable-arity args + (js!bool (comparison-conjuntion args ,sym)))))) (define-builtin-comparison > ">") (define-builtin-comparison < "<")