From: David Vázquez Date: Wed, 19 Feb 2014 01:05:07 +0000 (+0100) Subject: Boolean Lisp<->Javascript conversion X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=50599fbc81fc665124ebb66ad01be4166df23b0e;p=jscl.git Boolean Lisp<->Javascript conversion --- diff --git a/src/boot.lisp b/src/boot.lisp index d2c505f..a45bb73 100644 --- a/src/boot.lisp +++ b/src/boot.lisp @@ -52,6 +52,7 @@ (defconstant t 't) (defconstant nil 'nil) (%js-vset "nil" nil) +(%js-vset "t" t) (defmacro lambda (args &body body) `(function (lambda ,args ,@body))) diff --git a/src/prelude.js b/src/prelude.js index 9214436..9f78f4a 100644 --- a/src/prelude.js +++ b/src/prelude.js @@ -2,6 +2,8 @@ // contain runtime code that jscl assumes to exist. var window = this; + +var t; var nil; var lisp = {}; @@ -116,6 +118,10 @@ function Symbol(name, package_name){ function lisp_to_js (x) { if (typeof x == 'object' && 'length' in x && x.stringp == 1) return xstring(x); + else if (x === t) + return true; + else if (x === nil) + return false; else if (typeof x == 'function'){ // Trampoline calling the Lisp function return (function(){ @@ -131,6 +137,10 @@ function lisp_to_js (x) { function js_to_lisp (x) { if (typeof x == 'string') return make_lisp_string(x); + else if (x === true) + return t; + else if (x === false) + return nil; else if (typeof x == 'function'){ // Trampoline calling the JS function return (function(values, nargs){