From 1985734990b5c5ab3fd50277bff854ea3cd92b2c Mon Sep 17 00:00:00 2001 From: Teddy Date: Fri, 9 Aug 2013 22:18:39 +0800 Subject: fixed bug in `equal?` --- builtin.cpp | 11 ++++++----- main.cpp | 2 +- robust_test.scm | 3 +++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/builtin.cpp b/builtin.cpp index 98090e0..115377c 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -1335,9 +1335,8 @@ do { \ int otype = (a = *l1)->get_otype(); if (otype != (b = *l2)->get_otype()) return new BoolObj(false); - if (a == empty_list) - continue; - if (otype & CLS_PAIR_OBJ) + if (a != empty_list && b != empty_list && + otype & CLS_PAIR_OBJ) { *r1 = TO_PAIR(a)->car; INC1(r1); @@ -1363,7 +1362,7 @@ do { \ it = va->vec.begin(); it != va->vec.end(); it++) { - *r1 = TO_PAIR(a)->car; + *r1 = *it; INC1(r1); CHK1; } @@ -1372,7 +1371,7 @@ do { \ it = vb->vec.begin(); it != vb->vec.end(); it++) { - *r2 = TO_PAIR(b)->car; + *r2 = *it; INC2(r2); CHK2; } @@ -1418,6 +1417,8 @@ do { \ static_cast(b)->str) return new BoolObj(false); // (string=?) } + else if (a != b) + return new BoolObj(false); } return new BoolObj(true); } diff --git a/main.cpp b/main.cpp index 221941d..f9c09ae 100644 --- a/main.cpp +++ b/main.cpp @@ -6,7 +6,7 @@ #include int main() { - //freopen("in.scm", "r", stdin); + freopen("in.scm", "r", stdin); Tokenizor *tk = new Tokenizor(); ASTGenerator *ast = new ASTGenerator(); Evaluator *eval = new Evaluator(); diff --git a/robust_test.scm b/robust_test.scm index 7b7bfd4..152e380 100644 --- a/robust_test.scm +++ b/robust_test.scm @@ -218,3 +218,6 @@ src (if #f 1 ()) ; Error ; "Test double quotes in comments" (display " Test double quotes outside the comments ; ;; ; ; ") + +(equal? #(1 2 '()) #(1 2 '(1))) +(equal? #(1 2 '(1)) #(1 2 '(1))) -- cgit v1.2.3-70-g09d2