WIP - equalp with checks for circular lists

This commit is contained in:
Justin Ethier 2016-07-07 23:24:39 -04:00
parent 004c3c204b
commit 6794da5159

View file

@ -876,8 +876,18 @@ object memqp(void *data, object x, list l)
return boolean_f; return boolean_f;
} }
/**
*/
object equalp(object x, object y) 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)) { for (;; x = cdr(x), y = cdr(y)) {
if (equal(x, y)) if (equal(x, y))
return boolean_t; return boolean_t;
@ -885,8 +895,35 @@ object equalp(object x, object y)
(x == NULL) || (y == NULL) || (x == NULL) || (y == NULL) ||
type_of(x) != pair_tag || type_of(y) != pair_tag) type_of(x) != pair_tag || type_of(y) != pair_tag)
return boolean_f; return boolean_f;
// Both objects are lists at this point, compare cars
if (boolean_f == equalp(car(x), car(y))) if (boolean_f == equalp(car(x), car(y)))
return boolean_f; 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);
} }
} }