From d7e11a79df63bd65bc7f31d2747a6c8e59968b6c Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Sat, 22 Dec 2012 14:55:06 +0000 Subject: [PATCH] CAR and CDR work for NIL object --- lispstrack.lisp | 10 ++++++++-- test.lisp | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index 59e1c85..94f5a37 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -509,10 +509,16 @@ "; return (typeof tmp == 'object' && 'car' in tmp);})()"))) (define-compilation car (x) - (concat "(" (ls-compile x env fenv) ").car")) + (concat "(function () { var tmp = " (ls-compile x env fenv) + "; return tmp === " (ls-compile nil nil nil) "? " + (ls-compile nil nil nil) + ": tmp.car; })()")) (define-compilation cdr (x) - (concat "(" (ls-compile x env fenv) ").cdr")) + (concat "(function () { var tmp = " (ls-compile x env fenv) + "; return tmp === " (ls-compile nil nil nil) "? " + (ls-compile nil nil nil) + ": tmp.cdr; })()")) (define-compilation setcar (x new) (concat "((" (ls-compile x env fenv) ").car = " (ls-compile new env fenv) ")")) diff --git a/test.lisp b/test.lisp index d4ff11f..7652409 100644 --- a/test.lisp +++ b/test.lisp @@ -837,10 +837,16 @@ c(defmacro eval-when-compile (&body body) "; return (typeof tmp == 'object' && 'car' in tmp);})()"))) (define-compilation car (x) - (concat "(" (ls-compile x env fenv) ").car")) + (concat "(function () { var tmp = " (ls-compile x env fenv) + "; return tmp === " (ls-compile nil nil nil) "? " + (ls-compile nil nil nil) + ": tmp.car; })()")) (define-compilation cdr (x) - (concat "(" (ls-compile x env fenv) ").cdr")) + (concat "(function () { var tmp = " (ls-compile x env fenv) + "; return tmp === " (ls-compile nil nil nil) "? " + (ls-compile nil nil nil) + ": tmp.cdr; })()")) (define-compilation setcar (x new) (concat "((" (ls-compile x env fenv) ").car = " (ls-compile new env fenv) ")")) -- 1.7.10.4