[parenscript-devel] No-op LETs shouldn't thwart the expressionizer

Daniel Gackle danielgackle at gmail.com
Thu Jan 31 03:59:18 UTC 2013


These two forms seem like they ought to generate the same code, but don't:

  (defun foo ()
    (when (bar)
      (baz)))

  function foo() {
      return bar() ? baz() : null;
  };

  (defun foo ()
    (when (bar)
      (let ()
        (baz))))

  function foo() {
      if (bar()) {
          return baz();
      };
  };

Although one wouldn't write an empty LET by hand, macros that
accumulate bindings sometimes emit them. If those macros are
widely used in a program, one can lose quite a few desirable
'expressionizations' this way. I've committed a patch (see below)
to tweak the function TRY-EXPRESSIONIZING-IF? into exempting
empty LETs from the nesting heuristic it uses to decide what to
expressionize. Vladimir, please revise or revert it I did it wrong.

This came up because I'm trying to port my code to use the
MAYBE-ONCE-ONLY macro introduced in a5cf0df, rather than
a similar one I wrote. I'll post about that momentarily.

Daniel


diff --git a/src/special-operators.lisp b/src/special-operators.lisp
index 0267133..799d70f 100644
--- a/src/special-operators.lisp
+++ b/src/special-operators.lisp
@@ -222,7 +222,8 @@
               (try-expressionizing-if?
                (or (ignore-errors (ps-macroexpand x)) x) ;; fail
                (+ score (case (car exp)
-                          ((if cond let) 1)
+                          ((if cond) 1)
+                          (let (if (second exp) 1 0)) ;; ignore empty
binding list
                           ((progn) (1- (length (cdr exp))))
                           (otherwise 0))))))
         (t t)))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20130130/292e0b52/attachment.html>


More information about the parenscript-devel mailing list