Beispiel #1
0
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;
}
Beispiel #2
0
TEST_F (test_equal_p, list)
{
    rsexp actual = r_list (r,
                           2,
                           r_string_new (r, "a"),
                           r_int_to_sexp (42));

    rsexp expected = r_cons (r,
                             r_string_new (r, "a"),
                             r_cons (r,
                                     r_int_to_sexp (42),
                                     R_NULL));

    EXPECT_TRUE (equal_p (expected, actual));
}
Beispiel #3
0
static void primop_equal_p(long argc) {
	object tmp = *sp++;
	*sp = (equal_p(tmp,*sp))? true_object : false_object;
}