int equal_p(object o1, object o2) { if (eqv_p(o1,o2)) return 1; if (PAIR_P(o1)) { return PAIR_P(o2)&&equal_p(CAR(o1),CAR(o2))&&equal_p(CDR(o1),CDR(o2)); } else if (VECTOR_P(o1)) { if (VECTOR_P(o2)) { long max = VECTOR_LENGTH(o1); if (max == VECTOR_LENGTH(o2)) { object *e1 = VECTOR_ELEMENTS(o1), *e2 = VECTOR_ELEMENTS(o2); long i; for (i=0; i<max; i++) if (!equal_p(e1[i],e2[i])) return 0; return 1; } } } else if (STRING_P(o1)) { if (STRING_P(o2)) { long max = STRING_LENGTH(o1); if (max == STRING_LENGTH(o2)) { char *p1 = STRING_VALUE(o1); char *p2 = STRING_VALUE(o2); while (*p1 && *p2) { if (*p1++ != *p2++) return 0; } return (*p1 == *p2); } } } return 0; }
static void primop_eqv_p(long argc) { object tmp = *sp++; *sp = (eqv_p(tmp,*sp))? true_object : false_object; }
TEST_F (test_eqv_p, fixnum) { EXPECT_TRUE (eqv_p (r_cstr_to_number (r, "1/2"), r_cstr_to_number (r, "2/4"))); }
TEST_F (test_eqv_p, flonum) { EXPECT_TRUE (eqv_p (r_cstr_to_number (r, "#i1/2"), r_cstr_to_number (r, "0.5"))); }
TEST_F (test_eqv_p, small_int) { EXPECT_TRUE (eqv_p (r_int_to_sexp (42), r_int_to_sexp (42))); }