From c3273084cc4b1fa4657a5e52590825fd114841e4 Mon Sep 17 00:00:00 2001 From: Felix Perktold Date: Sun, 21 Dec 2025 22:15:30 +0100 Subject: improve car, cadr error handling --- lisp.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lisp.c b/lisp.c index e111c47..f107bea 100644 --- a/lisp.c +++ b/lisp.c @@ -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) { -- cgit v1.2.3