Fixed 'lisp' form to produce code that captures enclosing lexical scope correctly...
authorVladimir Sedach <vsedach@gmail.com>
Sun, 12 Apr 2009 01:57:19 +0000 (19:57 -0600)
committerVladimir Sedach <vsedach@gmail.com>
Sun, 12 Apr 2009 02:14:24 +0000 (20:14 -0600)
src/printer.lisp
src/special-forms.lisp
t/ps-tests.lisp

index 39dcc09..ef77c6f 100644 (file)
@@ -361,6 +361,7 @@ arguments, defines a printer for that form using the given body."
   (psw #\)))
 
 (defprinter js:escape (literal-js)
+  ;; literal-js should be a form that evaluates to a string containing valid JavaScript
   (psw literal-js))
 
 ;;; named statements
index 033405a..ad49e28 100644 (file)
@@ -721,4 +721,4 @@ lambda-list::=
 (define-ps-special-form lisp (lisp-form)
   ;; (ps (foo (lisp bar))) is in effect equivalent to (ps* `(foo ,bar))
   ;; when called from inside of ps*, lisp-form has access only to the dynamic environment (like for eval)
-  `(js:escape ,(ps1* lisp-form)))
+  `(js:escape (ps1* ,lisp-form)))
index 4e61258..86bc5c2 100644 (file)
@@ -785,3 +785,15 @@ try {
 (test-ps-js literal-array-1
   '(1 foo 3)
   "[1, 'foo', 3]")
+
+(test ps-lisp-expands-in-lexical-environment
+  (is (string= "5;" (let ((x 5)) (ps (lisp x))))))
+
+(test ps*-lisp-expands-in-null-lexical-environment
+  (signals error (let ((x 5)) (ps* '(lisp x)))))
+
+(test ps*-lisp-expands-in-dynamic-environment
+  (is (string= "1 + 2;" (let ((*print-level* 2)) (ps* '(+ 1 (lisp *print-level*)))))))
+
+(test ps-lisp-dynamic-environment
+  (is (string= "1 + 2;" (let ((*print-level* 2)) (ps (+ 1 (lisp *print-level*)))))))