<div dir="ltr"><div><div><div><div><div><div><div>Hi<br><br></div>It's my first post, so first of all, thanks to everyone who works on parenscript. It is a lifesaver.<br><br></div>If I 'use strict'; in the start of my scripts, they fail in some of the loops because parenscript is generating a 'with' (which is not allowed in strict mode). There is quite a nice explanation of why it isn't allowed here:<br>
<br><a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Functions_and_function_scope/Strict_mode">https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Functions_and_function_scope/Strict_mode</a><br>
<br>It is easy to change my code to use 'do' instead, and for now, that's what I've done, but it's a shame not to be able to use parenscript's very nice loop for writing javascript loops. I haven't looked at parenscript's code before this evening, but I think this is the relevant spot (in src/special-operators.lisp)<br>
<br></div>(defun compile-loop-body <br>...<br>(aif (sort (remove-duplicates *loop-scope-lexicals-captured*)<br> #'string< :key #'symbol-name)<br> `(ps-js:block<br> (ps-js:with<br>
,(compile-expression<br> `(create<br> ,@(loop for x in it<br> collect x<br> collect (when (member x loop-vars) x))))<br>
,compiled-body))<br> compiled-body)))<br><br></div>Here is an example of some lisp and the js which it generates:<br><br>(ps:ps (defun foo ()<br> (loop for i from 1 to 5<br> append (loop for j from 1 to 5<br>
collect (list i j))))) <br>==><br>"function foo() {<br> return (function () {<br> var append9 = [];<br> for (var i = 1; i <= 5; i += 1) {<br> with ({ i : i }) {<br>
^^^^^^^^^^<br> append9 = append9.concat((function () {<br> var collect10 = [];<br> for (var j = 1; j <= 5; j += 1) {<br> collect10['push']([i, j]);<br>
};<br> return collect10;<br> })());<br> };<br> };<br> return append9;<br> })();<br>};"<br><br></div>What is the point of even having the 'with ({ i : i })' in there ?? I have tried removing the form starting (ps-js:with ... ) and the code which is then generated runs fine and has no 'with', but of course it is probably breaking something else. I don't understand why it's there.<br>
<br></div>Regards,<br></div>Peter<br></div>