From f6c92edaaa7616d759165454b71542a6f7f62d10 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Wed, 23 May 2018 12:17:49 +0200 Subject: [PATCH] simplify --- lambda.y | 12 +++--------- print.c | 2 +- reduce.c | 2 +- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lambda.y b/lambda.y index cb14118..9155a8a 100644 --- 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 --- 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;"); } diff --git a/reduce.c b/reduce.c index 7bd170c..12914bf 100644 --- 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) { -- 2.20.1