simplify
authorMart Lubbers <mart@martlubbers.net>
Wed, 23 May 2018 10:17:49 +0000 (12:17 +0200)
committerMart Lubbers <mart@martlubbers.net>
Wed, 23 May 2018 10:17:49 +0000 (12:17 +0200)
lambda.y
print.c
reduce.c

index cb14118..9155a8a 100644 (file)
--- a/lambda.y
+++ b/lambda.y
@@ -90,9 +90,8 @@ struct lambda *make_numeral(unsigned int i)
 
 struct lambda *make_bool(bool b)
 {
-       return b
-               ? make_abstraction("a", false, make_abstraction("b", false, make_ident("a")))
-               : make_abstraction("a", false, make_abstraction("b", false, make_ident("b")));
+       return make_abstraction("a", false,
+               make_abstraction("b", false, make_ident(b ? "a" : "b")));
 }
 
 void decls_prepend(char *ident, struct lambda *value)
@@ -106,12 +105,9 @@ void decls_prepend(char *ident, struct lambda *value)
 
 struct lambda *decls_lookup(char *ident)
 {
-       struct decllist *c = decls;
-       while(c != NULL){
+       for(struct decllist *c = decls; c != NULL; c = c->next)
                if(strcmp(c->ident, ident) == 0)
                        return copy(c->value);
-               c = c->next;
-       }
        return make_ident(ident);
 }
 
@@ -137,7 +133,6 @@ lambda
                        decls_prepend($1->data.identifier.ident, $2);
                        printf("%s = ", $1->data.identifier.ident);
                        lambda_print($2, NULL);
-                       putchar('\n');
                        lambda_free($1);
                }
        | term
@@ -148,7 +143,6 @@ lambda
                                if(!lambda_reduce(&t, &t, false))
                                        break;
                        lambda_print(t, NULL);
-                       putchar('\n');
                        lambda_free(t);
                }
 func
diff --git a/print.c b/print.c
index f093ff5..9e6280c 100644 (file)
--- a/print.c
+++ b/print.c
@@ -42,5 +42,5 @@ void term_print(struct lambda *t, struct lambda *mark)
 void lambda_print(struct lambda *t, struct lambda *mark)
 {
        term_print(t, mark);
-       printf(";");
+       printf("\n;");
 }
index 7bd170c..12914bf 100644 (file)
--- a/reduce.c
+++ b/reduce.c
@@ -49,7 +49,7 @@ bool lambda_reduce(struct lambda **t, struct lambda **total, bool applicative)
                        lambda_free(*t);
                        *t = newt;
 
-                       printf("\nβ -> ");
+                       printf("β -> ");
                        return true;
                }
        } else if ((*t)->which == lambda_abs) {