7b7818923d1586b72f9054ceb2c9ad2cecfdf82b — Tim Morgan 1 year, 8 months ago 625ec6f
Rewrite list=? function to be a bit faster

We don't need to check the length on every recursion loop.
1 files changed, 7 insertions(+), 8 deletions(-)

M lib/scheme/base.scm
M lib/scheme/base.scm => lib/scheme/base.scm +7 -8
@@ 469,14 469,13 @@
 
     (define equal? '()) ; temporary
 
-    (define (list=? a b) ; don't export this
-      (if (= (length a) (length b))
-          (if (empty? a)
-              #t
-              (if (equal? (car a) (car b))
-                (list=? (cdr a) (cdr b))
-                #f))
-          #f))
+    (define (list=? list1 list2) ; don't export this
+      (letrec ((l=? (lambda (l1 l2)
+                      (or (empty? l1)
+                          (and (equal? (car l1) (car l2))
+                               (l=? (cdr l1) (cdr l2)))))))
+        (and (= (length list1) (length list2))
+             (l=? list1 list2))))
 
     (define (string=? . strings)
       (if (< (length strings) 2)