Introduced 'function' special form to further help with faking Lisp2
authorVladimir Sedach <vsedach@gmail.com>
Mon, 8 Jun 2009 04:52:58 +0000 (22:52 -0600)
committerVladimir Sedach <vsedach@gmail.com>
Mon, 8 Jun 2009 04:52:58 +0000 (22:52 -0600)
in JavaScript.

Previously, 'apply,' among others, did not recognize the second
namespace as introduced by flet/labels. Thanks to Scott Bell for the
bug report:
http://common-lisp.net/pipermail/parenscript-devel/2009-June/000529.html

src/special-forms.lisp
t/ps-tests.lisp

index a7c7d28..9a324e2 100644 (file)
@@ -392,6 +392,9 @@ lambda-list::=
              ,@body)
      :expecting expecting)))
 
+(define-ps-special-form function (fn-name)
+  (compile-parenscript-form (maybe-rename-local-function fn-name) :expecting expecting))
+
 (defvar *defun-setf-name-prefix* "__setf_")
 
 (defpsmacro defun-setf (setf-name lambda-list &body body)
index bc60917..291a95e 100644 (file)
@@ -1065,3 +1065,44 @@ x + x;")
   (symbol-macrolet ((x y))
     (return (if x x x)))
   "return y ? y : y;")
+
+(test-ps-js flet-apply
+  (flet ((foo () 'bar))
+    (apply (function foo) nil))
+  "var foo1 = function () {
+    'bar';
+};
+foo1.apply(this, null);")
+
+(test-ps-js let-apply
+  (let ((foo (lambda () (return 1))))
+    (let ((foo (lambda () (return 2))))
+      (apply foo nil)))
+  "var foo = function () {
+    return 1;
+};
+var foo1 = function () {
+    return 2;
+};
+foo1.apply(this, null);")
+
+(test-ps-js flet-let
+  (flet ((x (x) (return (1+ x))))
+    (let ((x 2))
+      (x x)))
+  "var x1 = function (x) {
+    return x + 1;
+};
+var x = 2;
+x1(x);")
+
+(test-ps-js let-flet
+  (let ((x 2))
+    (flet ((x (x) (return (1+ x))))
+      (x x)))
+  "var x = 2;
+var x1 = function (x) {
+    return x + 1;
+};
+x1(x);")
+