From: Andrea Griffini Date: Tue, 30 Apr 2013 06:54:21 +0000 (+0200) Subject: better equal implementation with support for conses, vectors, strings X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=218d9ab258ad337f7ce12145415773cf3d5227e0;p=jscl.git better equal implementation with support for conses, vectors, strings --- diff --git a/src/boot.lisp b/src/boot.lisp index 3a9ce45..37a0cf0 100644 --- a/src/boot.lisp +++ b/src/boot.lisp @@ -565,6 +565,23 @@ ((symbolp x) (symbol-name x)) (t (char-to-string x)))) +(defun equal (x y) + (cond + ((eql x y) t) + ((consp x) + (and (consp y) + (equal (car x) (car y)) + (equal (cdr x) (cdr y)))) + ((arrayp x) + (and (arrayp y) + (let ((n (length x))) + (when (= (length y) n) + (dotimes (i n) + (unless (equal (aref x i) (aref y i)) + (return-from equal nil))) + t)))) + (t nil))) + (defun string= (s1 s2) (equal s1 s2)) diff --git a/src/compiler.lisp b/src/compiler.lisp index a6c451b..94f5c7a 100644 --- a/src/compiler.lisp +++ b/src/compiler.lisp @@ -1410,7 +1410,6 @@ (code "(" x ").toString()")) (define-builtin eq (x y) (js!bool (code "(" x " === " y ")"))) -(define-builtin equal (x y) (js!bool (code "(" x " == " y ")"))) (define-builtin char-to-string (x) (type-check (("x" "number" x))