From 4c4df6613e2f96e384615ec1c1bcc0df53fa5bc8 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Fri, 31 Jan 2025 18:47:46 +0200 Subject: allow defines in curly braces --- examples/fib.lyn | 12 ++++++++++++ src/lyn.c | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 examples/fib.lyn diff --git a/examples/fib.lyn b/examples/fib.lyn new file mode 100644 index 0000000..b24f18b --- /dev/null +++ b/examples/fib.lyn @@ -0,0 +1,12 @@ +define (fib n) { + if (< n 2) { + get 1 + } { + define f1 (fib (- n 1)) + define f2 (fib (- n 2)) + + f1 f2 + } +} + +display (fib 42) +newline diff --git a/src/lyn.c b/src/lyn.c index b74e19f..2eb8169 100644 --- a/src/lyn.c +++ b/src/lyn.c @@ -13,7 +13,7 @@ static int eval_group(struct lyn *lyn, struct lyn_value value) { - fprintf(lyn->output, "(begin"); + fprintf(lyn->output, "((lambda () (begin"); lyn->depth++; foreach_vec(gi, value.args) { @@ -24,7 +24,7 @@ static int eval_group(struct lyn *lyn, struct lyn_value value) fprintf(lyn->output, ")"); } - fprintf(lyn->output, "\n%*s)", 2 * lyn->depth, " "); + fprintf(lyn->output, "\n%*s)))", 2 * lyn->depth, " "); lyn->depth--; return 0; -- cgit v1.2.3