diff options
| author | Felix Perktold <Felix.Perktold@student.uibk.ac.at> | 2026-01-21 19:48:47 +0100 |
|---|---|---|
| committer | Felix Perktold <Felix.Perktold@student.uibk.ac.at> | 2026-01-21 19:48:47 +0100 |
| commit | e3b8eded6cf924e2f1e532f0db1aef899b451ccf (patch) | |
| tree | a7a1098eeac676aaed58d0013d40c3a8aa0c88e4 /lisp.c | |
| parent | 77df6486f9ed77e38a554cdaa6e28bea348f4788 (diff) | |
fix integers-from style infinite lists
Diffstat (limited to 'lisp.c')
| -rw-r--r-- | lisp.c | 27 |
1 files changed, 9 insertions, 18 deletions
@@ -91,16 +91,8 @@ value *force_thunk(value *v) { return v; } if(v->as.thunk.cached) { - printf("\nDEBUG: thunk "); - print_value(v->as.thunk.expr); - printf(" was already cached as: "); - println_value(v->as.thunk.cached); return v->as.thunk.cached; } - printf("\nDEBUG: thunk "); - print_value(v->as.thunk.expr); - printf(" is now cached as: "); - println_value(v->as.thunk.cached); v->as.thunk.cached = eval(v->as.thunk.env, v->as.thunk.expr); return v; @@ -169,22 +161,21 @@ void print_value(value *val) { break; case VT_PAIR: - // DOTTED: - //printf("("); - //print_value(val->as.pair.car); - //printf(" . "); - //print_value(val->as.pair.cdr); - //printf(")"); - - // LISTS: printf("("); - print_value(car(val)); + print_value(force_thunk(car(val))); value *p_cdr = cdr(val); - while (p_cdr->type == VT_PAIR) { + while (p_cdr->type == VT_PAIR || p_cdr->type == VT_THUNK) { + while (p_cdr->type == VT_THUNK) { + p_cdr = force_thunk(p_cdr); + } + if (p_cdr->type != VT_PAIR) { + break; + } printf(" "); print_value(car(p_cdr)); p_cdr = cdr(p_cdr); } + if(p_cdr->type != VT_NIL) { printf(" . "); print_value(p_cdr); |
