Hi
It's my first post, so first of all, thanks to everyone who works on parenscript. It is a lifesaver.
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:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Functions_and_function_scope/Strict_mode
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)
(defun compile-loop-body
...
(aif (sort (remove-duplicates *loop-scope-lexicals-captured*)
#'string< :key #'symbol-name)
`(ps-js:block
(ps-js:with
,(compile-expression
`(create
,@(loop for x in it
collect x
collect (when (member x loop-vars) x))))
,compiled-body))
compiled-body)))
Here is an example of some lisp and the js which it generates:
(ps:ps (defun foo ()
(loop for i from 1 to 5
append (loop for j from 1 to 5
collect (list i j)))))
==>
"function foo() {
return (function () {
var append9 = [];
for (var i = 1; i <= 5; i += 1) {
with ({ i : i }) {
^^^^^^^^^^
append9 = append9.concat((function () {
var collect10 = [];
for (var j = 1; j <= 5; j += 1) {
collect10['push']([i, j]);
};
return collect10;
})());
};
};
return append9;
})();
};"
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.