Hi Vladimir,
Another tricky area for implicit return is in IF/WHEN/UNLESS. What happens currently is that when a conditional is in an expression place (such as after a RETURN statement), it is converted into a ternary expression.
This works when the branches of the conditional contain only assignments and expressions, but you get a syntax error if there is a switch, for, or while statement in the branch body.
I'm not sure how to handle this in the general expression-place scenario, but it seems like implicit return should handle all of the conditional branches -- something like this:
(ps (lambda () (when x y))) => "function () { return x ? y : null; };"
becomes:
(ps (lambda () (when x y))) => "if (x) { return y; };"
or perhaps:
(ps (lambda () (when x y))) => "if (x) { return y; } else { return null; };"
- Scott
On 2009-11-04, at 12:57 PM, Vladimir Sedach wrote:
Hello,
Many of you have been asking for this for a long time, and based on feedback (as well as my own experience) the lack of this feature has been the biggest cause of bugs in PS code, so it's with a bit of joy that I just pushed out a patch to add implicit returns to PS functions (including lambdas and flet/labels) to the repository just now. Please try it out and report any bugs you find!
Thank you, Vladimir
parenscript-devel mailing list parenscript-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
On 2009-11-05, at 12:20 PM, sblist@me.com wrote:
Hi Vladimir,
Another tricky area for implicit return is in IF/WHEN/UNLESS. What happens currently is that when a conditional is in an expression place (such as after a RETURN statement), it is converted into a ternary expression.
This is still the case as of the latest commit, so code like this fails:
(ps (lambda () (cond ((foo? x) (loop for y in x do (foo y))) ((bar? x) x) (t t))))
..and this as well:
(ps (lambda () (cond ((foo? x) (try x (:catch (e) e))) ((bar? x) x) (t t))))
- Scott
Just pushed patches that fix RETURNing of cond and symbol-macrolet. Let me know if you catch anything else amiss.
Thank you, Vladimir
2009/11/23 sblist@me.com:
On 2009-11-05, at 12:20 PM, sblist@me.com wrote:
Hi Vladimir,
Another tricky area for implicit return is in IF/WHEN/UNLESS. What happens currently is that when a conditional is in an expression place (such as after a RETURN statement), it is converted into a ternary expression.
This is still the case as of the latest commit, so code like this fails:
(ps (lambda () (cond ((foo? x) (loop for y in x do (foo y))) ((bar? x) x) (t t))))
..and this as well:
(ps (lambda () (cond ((foo? x) (try x (:catch (e) e))) ((bar? x) x) (t t))))
- Scott
parenscript-devel mailing list parenscript-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
Hi Vladimir,
On 2009-11-27, at 5:24 PM, Vladimir Sedach wrote:
Just pushed patches that fix RETURNing of cond and symbol-macrolet. Let me know if you catch anything else amiss.
Thank you, Vladimir
2009/11/23 sblist@me.com:
On 2009-11-05, at 12:20 PM, sblist@me.com wrote: ...
This is still the case as of the latest commit, so code like this fails:
(ps (lambda () (cond ((foo? x) (loop for y in x do (foo y))) ((bar? x) x) (t t))))
This form now emits valid JS. However, using DOLIST instead of LOOP here causes a syntax error:
(ps (lambda () (cond ((foo? x) (dolist (y x) (foo y))) ((bar? x) x) (t t)))) => "function () { if (foowhat(x)) { return for (var y = null, _js_idx1288 = 0; _js_idx1288 < x.length; _js_i\ dx1288 += 1) { y = x[_js_idx1288]; foo(y); }; } else if (barwhat(x)) { return x; } else { return true; }; };"
Here is some more curious DOLIST behavior:
SKYSHEET> (ps (lambda () (dolist (arg args) (foo arg)))) "function () { for (var arg = null, _js_idx1289 = 0; _js_idx1289 < args.length; _js_idx1289\ += 1) { arg = args[_js_idx1289]; foo(arg); }; };" SKYSHEET> (ps (lambda () (let ((x y)) (dolist (arg args) (foo arg))))) "function () { var x = y; return for (var arg = null, _js_idx1290 = 0; _js_idx1290 < args.length; _js_\ idx1290 += 1) { arg = args[_js_idx1290]; foo(arg); }; };"
- Scott
I pushed a fix that should handle the iteration special forms correctly (the previous code had macros and not the special forms to which they expanded in the statements list). Thanks again for the QA.
Vladimir
2009/11/29 sblist@me.com:
Hi Vladimir,
On 2009-11-27, at 5:24 PM, Vladimir Sedach wrote:
Just pushed patches that fix RETURNing of cond and symbol-macrolet. Let me know if you catch anything else amiss.
Thank you, Vladimir
2009/11/23 sblist@me.com:
On 2009-11-05, at 12:20 PM, sblist@me.com wrote: ...
This is still the case as of the latest commit, so code like this fails:
(ps (lambda () (cond ((foo? x) (loop for y in x do (foo y))) ((bar? x) x) (t t))))
This form now emits valid JS. However, using DOLIST instead of LOOP here causes a syntax error:
(ps (lambda () (cond ((foo? x) (dolist (y x) (foo y))) ((bar? x) x) (t t)))) => "function () { if (foowhat(x)) { return for (var y = null, _js_idx1288 = 0; _js_idx1288 < x.length; _js_i\ dx1288 += 1) { y = x[_js_idx1288]; foo(y); }; } else if (barwhat(x)) { return x; } else { return true; }; };"
Here is some more curious DOLIST behavior:
SKYSHEET> (ps (lambda () (dolist (arg args) (foo arg)))) "function () { for (var arg = null, _js_idx1289 = 0; _js_idx1289 < args.length; _js_idx1289\ += 1) { arg = args[_js_idx1289]; foo(arg); }; };" SKYSHEET> (ps (lambda () (let ((x y)) (dolist (arg args) (foo arg))))) "function () { var x = y; return for (var arg = null, _js_idx1290 = 0; _js_idx1290 < args.length; _js_\ idx1290 += 1) { arg = args[_js_idx1290]; foo(arg); }; };"
- Scott
parenscript-devel mailing list parenscript-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
parenscript-devel@common-lisp.net