change printing
[lambda.git] / reduce.c
index bbe52de..12914bf 100644 (file)
--- a/reduce.c
+++ b/reduce.c
@@ -16,8 +16,7 @@ void lambda_beta(struct lambda *binding, struct lambda **body, struct lambda *ta
        case lambda_ident:
                if((*body)->data.identifier.binding == binding){
                        lambda_free(*body);
-                       *body = target;
-                       target->refcount++;
+                       *body = copy(target);
                }
                break;
        case lambda_abs:
@@ -42,21 +41,15 @@ bool lambda_reduce(struct lambda **t, struct lambda **total, bool applicative)
                        if(lhs(t)->data.abstraction.strict)
                                lambda_reduce(&rhs(t), total, true);
 
-                       if(lhs(t) == rhs(t)){
-                               lhs(t)->refcount--;
-                               rhs(t) = copy(rhs(t));
-                       }
-
                        //In this abstraction we substitute the result with the rhs
                        lambda_print(*total, *t);
                        lambda_beta(lhs(t), &lhs(t)->data.abstraction.expr, rhs(t), *total);
 
-                       struct lambda *newt = lhs(t)->data.abstraction.expr;
-                       lhs(t)->data.abstraction.expr->refcount++;
+                       struct lambda *newt = copy(lhs(t)->data.abstraction.expr);
                        lambda_free(*t);
                        *t = newt;
 
-                       printf("\nβ -> ");
+                       printf("β -> ");
                        return true;
                }
        } else if ((*t)->which == lambda_abs) {