[heresy-devel] Equality testing.
Matt Lamari
matthew.lamari at gmail.com
Fri Sep 5 21:08:52 UTC 2008
(note - has to be read in heresy namespace, i.e. add it to the file)
I believe it works correctly with sub-lists too.
Also note - consumes stack - when I get time I'll rewrite it in
continuation-calling form. It does not consume stack based on list
"length"; but on list-of-list depth. I'll also optimize it better for
speed (expand out/not use those readpoints and their performance hit).
(defun equal/ (a b)
(let ((infinite (iterate/ #'identity nil))
(end (cons nil nil))
(a-is-list (listp/ a))
(b-is-list (listp/ b)))
(cond
((and a-is-list b-is-list)
(let ((a (read-point-built (to-lazy-list a)))
(b (read-point-built (to-lazy-list b))))
(unless
(loop while not (or (read-point-at-end a) (read-point-at-end
b)) do
(unless (equal/ (read-point-value a) (read-point-value b))
(return-from nil t))
(setq a (read-point-advanced a))
(setq b (read-point-advanced b)))
(not (or (read-point-at-end a) (read-point-at-end b))))))
((or a-is-list b-is-list) nil)
(t (equal a b)))))
Robin Lee Powell wrote:
> * (equal (LIST/ 'B 'A 'Q '(C 1)) (LIST/ 'B 'A 'Q '(C 1)))
> NIL
>
> So, umm, how do I do that? Convert to a regular list first?
>
> -Robin
>
>
More information about the heresy-devel
mailing list