From 98d94399ef4613cbcc82b23ec5a60781bc2c6a35 Mon Sep 17 00:00:00 2001 From: rayslava Date: Sun, 20 Jan 2013 01:11:16 +0400 Subject: [PATCH] Comparisons on lists --- ecmalisp.lisp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/ecmalisp.lisp b/ecmalisp.lisp index 244d07c..39750b9 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -1554,11 +1554,24 @@ (define-builtin mod (x y) (num-op-num x "%" y)) -(define-builtin < (x y) (js!bool (num-op-num x "<" y))) -(define-builtin > (x y) (js!bool (num-op-num x ">" y))) -(define-builtin = (x y) (js!bool (num-op-num x "==" y))) -(define-builtin <= (x y) (js!bool (num-op-num x "<=" y))) -(define-builtin >= (x y) (js!bool (num-op-num x ">=" y))) +(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-builtin-comparison > ">") +(define-builtin-comparison < "<") +(define-builtin-comparison >= ">=") +(define-builtin-comparison <= "<=") +(define-builtin-comparison = "==") +(define-builtin-comparison equal "==") +(define-builtin-comparison eq "===") (define-builtin numberp (x) (js!bool (concat "(typeof (" x ") == \"number\")"))) @@ -1640,10 +1653,6 @@ (define-builtin lambda-code (x) (concat "(" x ").toString()")) - -(define-builtin eq (x y) (js!bool (concat "(" x " === " y ")"))) -(define-builtin equal (x y) (js!bool (concat "(" x " == " y ")"))) - (define-builtin char-to-string (x) (type-check (("x" "number" x)) "String.fromCharCode(x)")) -- 1.7.10.4