From: Mart Lubbers Date: Wed, 16 May 2018 12:08:32 +0000 (+0200) Subject: Change evaluation strategy to normal order X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=300960def6015f0d0f7e6f649855babe74fd51e9;p=lambda.git Change evaluation strategy to normal order --- diff --git a/lambda.y b/lambda.y index 830fa99..007fb2d 100644 --- a/lambda.y +++ b/lambda.y @@ -51,7 +51,6 @@ struct lambda *make_application(struct lambda *t1, struct lambda *t2) void decls_prepend(char *ident, struct lambda *value) { - printf("add: %s\n", ident); struct decllist *head = malloc(sizeof (struct decllist)); head->next = decls; head->ident = ident; @@ -61,14 +60,12 @@ void decls_prepend(char *ident, struct lambda *value) struct lambda *decls_lookup(char *ident) { - printf("lookup: %s\n", ident); struct decllist *c = decls; while(c != NULL){ if(strcmp(c->ident, ident) == 0) return copy(c->value); c = c->next; } - printf("Notfound\n"); return make_ident(ident); } diff --git a/preamble b/preamble new file mode 100644 index 0000000..05ea3ca --- /dev/null +++ b/preamble @@ -0,0 +1,4 @@ +I=\x.x; +K=\x y.x; +S=\x y z.x y(x z); +O=(\x.x x)(\x.x x); diff --git a/reduce.c b/reduce.c index 8537a20..7335bfd 100644 --- a/reduce.c +++ b/reduce.c @@ -45,8 +45,6 @@ void lambda_reduce(struct lambda *t, struct lambda *total, int *maxdepth) //If the first argument is an abstraction, we apply t1 = t->data.application.expr1; t2 = t->data.application.expr2; - lambda_reduce(t1, total, maxdepth); - lambda_reduce(t2, total, maxdepth); if(t1->which == lambda_abs){ subst(t1->data.abstraction.ident, t1->data.abstraction.expr, t2, total); (*maxdepth)--; @@ -57,6 +55,8 @@ void lambda_reduce(struct lambda *t, struct lambda *total, int *maxdepth) lambda_print(total); lambda_reduce(t, total, maxdepth); } + lambda_reduce(t1, total, maxdepth); + lambda_reduce(t, total, maxdepth); break; } }