summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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) {