Skip to content

Commit 8796264

Browse files
committed
Implement most of the equal? predicate
This is part of issue #1
1 parent a579133 commit 8796264

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

scheme-core.lisp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,24 @@ rules provided in the r7rs-small specification.
7575
(t (eq x y))))
7676

7777
;;; TODO: Must always terminate even if the list is circular.
78-
;;;
79-
;;; TODO: recursively compare sequences
78+
(defun list-equal? (x y)
79+
(or (and (null x) (eql x y))
80+
(and (equal? (car x) (car y))
81+
(list-equal? (cdr x) (cdr y)))))
82+
83+
(defun vector-equal? (x y)
84+
(and (typep y (type-of x))
85+
(= (length x) (length y))
86+
(loop :for a :across x
87+
:for b :across y
88+
:always (equal? a b))))
89+
90+
;;; TODO: use a sequence-generic comparison when extensible-sequences is used
8091
(defun equal? (x y)
81-
;; TODO: Stub
82-
(eqv? x y))
92+
(typecase x
93+
(list (and (listp y) (list-equal? x y)))
94+
(vector (and (vectorp y) (vector-equal? x y)))
95+
(t (eqv? x y))))
8396

8497
(defun coerce-subseq (sequence result-type &optional start end)
8598
"Coerces a subsequence into the result type"

0 commit comments

Comments
 (0)