summaryrefslogtreecommitdiff
path: root/lisp.c
diff options
context:
space:
mode:
authorFelix Perktold <Felix.Perktold@student.uibk.ac.at>2025-12-21 22:15:30 +0100
committerFelix Perktold <Felix.Perktold@student.uibk.ac.at>2025-12-21 22:15:30 +0100
commitc3273084cc4b1fa4657a5e52590825fd114841e4 (patch)
treef678f6294b73f4cb56179bd03a1a05197d88c073 /lisp.c
parentc7878cd824360c6bf8a8e987acfa6a31140e9d69 (diff)
improve car, cadr error handling
Diffstat (limited to 'lisp.c')
-rw-r--r--lisp.c19
1 files 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) {