From c740ece288c3fb6f858a911222fd63caf95c4eea Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 25 Aug 2024 15:46:56 +0300 Subject: lambda work, closures work, everything works --- src/value.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/value.c') diff --git a/src/value.c b/src/value.c index 3c06fa3..d7df858 100644 --- a/src/value.c +++ b/src/value.c @@ -136,10 +136,21 @@ static int cons_print(char *buf, size_t buf_sz, struct cons *cons) int offset = 0; buf[offset++] = '('; offset += value_string(cons->left, buf_sz-offset, buf+offset); - buf[offset++] = ' '; - buf[offset++] = '.'; - buf[offset++] = ' '; - offset += value_string(cons->right, buf_sz-offset, buf+offset); + + value_t right = cons->right; + while(right->type == VALUE_CONS) { + buf[offset++] = ' '; + offset += value_string(right->value.cons.left, + buf_sz-offset, buf+offset); + right = right->value.cons.right; + } + + if(right->type != VALUE_NIL) { + buf[offset++] = ' '; + buf[offset++] = '.'; + buf[offset++] = ' '; + offset += value_string(right, buf_sz-offset, buf+offset); + } buf[offset++] = ')'; return offset; -- cgit v1.2.3