From: David Vazquez Date: Sat, 22 Dec 2012 14:55:06 +0000 (+0000) Subject: CAR and CDR work for NIL object X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=d7e11a79df63bd65bc7f31d2747a6c8e59968b6c;p=jscl.git CAR and CDR work for NIL object --- 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) ")"))