better equal implementation with support for conses, vectors, strings
authorAndrea Griffini <agriff@tin.it>
Tue, 30 Apr 2013 06:54:21 +0000 (08:54 +0200)
committerAndrea Griffini <agriff@tin.it>
Tue, 30 Apr 2013 09:12:37 +0000 (11:12 +0200)
src/boot.lisp
src/compiler.lisp

index 3a9ce45..37a0cf0 100644 (file)
         ((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))
 
index a6c451b..94f5c7a 100644 (file)
   (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))