From bf83fd3d91e6ced85ae23f050bb57de64c81f800 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Sat, 17 Aug 2019 11:02:25 +0100 Subject: [PATCH] (car-nil-legal t) This is a joke only afficionados of Portable Standard Lisp will understand. --- src/beowulf/eval.clj | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/beowulf/eval.clj b/src/beowulf/eval.clj index fbe0331..5d78087 100644 --- a/src/beowulf/eval.clj +++ b/src/beowulf/eval.clj @@ -27,19 +27,25 @@ (if (or (symbol? x) (number? x)) 'T NIL)) (defn CAR + "Return the item indicated by the first pointer of a pair. NIL is treated + specially: the CAR of NIL is NIL." [x] - (if - (instance? beowulf.cons_cell.ConsCell x) - (.CAR x) + (cond + (= x NIL) NIL + (instance? beowulf.cons_cell.ConsCell x) (.CAR x) + :else (throw (Exception. (str "Cannot take CAR of `" x "` (" (.getName (.getClass x)) ")"))))) (defn CDR + "Return the item indicated by the second pointer of a pair. NIL is treated + specially: the CDR of NIL is NIL." [x] - (if - (instance? beowulf.cons_cell.ConsCell x) - (.CDR x) + (cond + (= x NIL) NIL + (instance? beowulf.cons_cell.ConsCell x) (.CDR x) + :else (throw (Exception. (str "Cannot take CDR of `" x "` (" (.getName (.getClass x)) ")")))))