From c90b70190d55a8eb5e57db4548577217fb1ee4d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Sun, 20 Jan 2013 17:39:37 +0000 Subject: [PATCH] Fix n-arity comparisons --- ecmalisp.lisp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) 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 < "<") -- 1.7.10.4