diff --git a/module/mes/base.mes b/module/mes/base.mes index f3df2169..789351b1 100644 --- a/module/mes/base.mes +++ b/module/mes/base.mes @@ -91,17 +91,6 @@ (define (and=> value procedure) (and value (procedure value))) (define eqv? eq?) -(define (equal2? a b) - (if (and (null? a) (null? b)) #t - (if (and (pair? a) (pair? b)) - (and (equal2? (car a) (car b)) - (equal2? (cdr a) (cdr b))) - (if (and (string? a) (string? b)) - (eq? (string->symbol a) (string->symbol b)) - (if (and (vector? a) (vector? b)) - (equal2? (vector->list a) (vector->list b)) - (eq? a b)))))) - (define (equal? . x) (if (or (null? x) (null? (cdr x))) #t (if (null? (cddr x)) (equal2? (car x) (cadr x)) diff --git a/src/lib.c b/src/lib.c index f660b8f6..5c03111c 100644 --- a/src/lib.c +++ b/src/lib.c @@ -268,3 +268,33 @@ memq (SCM x, SCM a) return a != cell_nil ? a : cell_f; } +SCM +equal2_p (SCM a, SCM b) +{ + if (a == cell_nil && b == cell_nil) + return cell_t; + if (TYPE (a) == TPAIR && TYPE (b) == TPAIR) + return equal2_p (CAR (a), CAR (b)) == cell_t + && equal2_p (CDR (a), CDR (b)) == cell_t + ? cell_t : cell_f; + if (TYPE (a) == TSTRING && TYPE (b) == TSTRING) + return equal2_p (STRING (a), STRING (b)); + if (TYPE (a) == TVECTOR && TYPE (b) == TVECTOR) + { + if (LENGTH (a) != LENGTH (b)) + return cell_f; + for (int i=0; i < LENGTH (a); i++) + { + SCM ai = VECTOR (a) + i; + SCM bi = VECTOR (b) + i; + if (TYPE (ai) == TREF) + ai = REF (ai); + if (TYPE (bi) == TREF) + bi = REF (bi); + if (equal2_p (ai, bi) == cell_f) + return cell_f; + } + return cell_t; + } + return eq_p (a, b); +}