diff options
| author | Felix Perktold <Felix.Perktold@student.uibk.ac.at> | 2025-12-21 22:15:30 +0100 |
|---|---|---|
| committer | Felix Perktold <Felix.Perktold@student.uibk.ac.at> | 2025-12-21 22:15:30 +0100 |
| commit | c3273084cc4b1fa4657a5e52590825fd114841e4 (patch) | |
| tree | f678f6294b73f4cb56179bd03a1a05197d88c073 /lisp.c | |
| parent | c7878cd824360c6bf8a8e987acfa6a31140e9d69 (diff) | |
improve car, cadr error handling
Diffstat (limited to 'lisp.c')
| -rw-r--r-- | lisp.c | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -66,16 +66,25 @@ value *cons(value *car, value *cdr) { } value *car(value *cons) { - //TODO: more robust implementation with error catching - return cons->as.pair.car; + if (cons->type == VT_PAIR) { + return cons->as.pair.car; + } + printf("not a pair: "); + print_value(cons); + printf("\n"); + return make_nil(); } value *cdr(value *cons) { - //TODO: more robust implementation with error catching - return cons->as.pair.cdr; + if (cons->type == VT_PAIR) { + return cons->as.pair.cdr; + } + printf("not a pair: "); + print_value(cons); + printf("\n"); + return make_nil(); } - void *print_value(value *val){ char *str; switch (val->type) { |
