From 6794da515963d17a0cff8acc96ffa285995f14c7 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 7 Jul 2016 23:24:39 -0400 Subject: [PATCH] WIP - equalp with checks for circular lists --- runtime.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/runtime.c b/runtime.c index 427a5372..4f7c97d6 100644 --- a/runtime.c +++ b/runtime.c @@ -876,8 +876,18 @@ object memqp(void *data, object x, list l) return boolean_f; } +/** + */ object equalp(object x, object y) { + object slow_lis = x, fast_lis; + int second_cycle = 0; + +// if (Cyc_is_pair(x) == boolean_t && +// Cyc_is_pair(cdr(x)) == boolean_t){ +// fast_lis = cdr(x); +// } + for (;; x = cdr(x), y = cdr(y)) { if (equal(x, y)) return boolean_t; @@ -885,8 +895,35 @@ object equalp(object x, object y) (x == NULL) || (y == NULL) || type_of(x) != pair_tag || type_of(y) != pair_tag) return boolean_f; + + // Both objects are lists at this point, compare cars if (boolean_f == equalp(car(x), car(y))) return boolean_f; + +// // If there is no cycle, keep checking equality +// if (fast_lis == NULL || +// Cyc_is_pair(fast_lis) == boolean_f || +// cdr(fast_lis) == NULL || +// Cyc_is_pair(cdr(fast_lis)) == boolean_f || +// cddr(fast_lis) == NULL){ +// continue; +// } +// +// // If there is a cycle, handle it +// if (slow_lis == fast_lis) { +// // if this is y, both lists have cycles and are equal, return #t +// if (second_cycle) +// return boolean_t; +// // if this is x, keep going and check for a cycle in y +// second_cycle = 1; +// slow_lis = y; +// if (Cyc_is_pair(y) == boolean_t) { +// fast_lis = cdr(y); +// } +// continue; +// } +// slow_lis = cdr(slow_lis); +// fast_lis = cddr(fast_lis); } }