[parenscript-devel] Bug fix: WITH-SLOTS and multiple evaluation

Daniel Gackle danielgackle at gmail.com
Sat Mar 2 01:13:30 UTC 2013


WITH-SLOTS had a problem with multiple evaluation:

(ps (with-slots (a b) (foo) (+ a b)))
  => "foo().a + foo().b;"

I pushed a fix for that. Patch below.

Daniel


commit 305778c609dd6102b4a313ef436985551c29ee18
Author: Daniel Gackle <danielgackle at gmail.com>
Date:   Fri Mar 1 17:17:04 2013 -0700

    Fixed bug: multiple evaluation in WITH-SLOTS.

diff --git a/src/macros.lisp b/src/macros.lisp
index 5537872..b75f4b0 100644
--- a/src/macros.lisp
+++ b/src/macros.lisp
@@ -140,10 +140,11 @@
            (if (listp slot)
                (second slot)
                slot)))
-    `(symbol-macrolet ,(mapcar (lambda (slot)
-                                 `(,(slot-var slot) (getprop ,object
',(slot-symbol slot))))
-                               slots)
-       , at body)))
+    (maybe-once-only (object)
+      `(symbol-macrolet ,(mapcar (lambda (slot)
+                                   `(,(slot-var slot) (getprop ,object
',(slot-symbol slot))))
+                                 slots)
+         , at body))))

 ;;; multiple values

diff --git a/t/output-tests.lisp b/t/output-tests.lisp
index 361cd8b..f2d856c 100644
--- a/t/output-tests.lisp
+++ b/t/output-tests.lisp
@@ -141,6 +141,13 @@
     (+ a b c))
   "this.a + this.b + this.c;")

+(test-ps-js with-slots-single-eval
+  (lambda () (with-slots (a b) (foo) (+ a b)))
+  "(function () {
+    var object1 = foo();
+    return object1.a + object1.b;
+});")
+
 (test-ps-js object-literal-quoted-symbols
   (create 'test "bang" 'symbol-saved-my-life "parenscript")
   "({ 'test' : 'bang', 'symbolSavedMyLife' : 'parenscript' });")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20130301/bf928d77/attachment.html>


More information about the parenscript-devel mailing list