Hi,
Problem number 1:
This form
(ps (loop :for i :from 0 :do (print i)))
generates:
(function () {
for (var i = 0; i <= null; i += 1) {
print(i);
};
})();
I fixed it locally by changing for-from
(defun for-from (from-key var state)
(unless (atom var)
(err "an atom after FROM" var))
(let ((start (eat state))
(op (loop-case from-key (:downfrom '-) (otherwise '+)))
(test-op nil)
(by nil)
(end nil))
(loop while (member (as-keyword (peek state)) '(:to :below :downto
:above :by)) do
(let ((term (eat state)))
(if (eq (as-keyword term) :by)
(setf by (eat state))
(setf op (loop-case term ((:downto :above) '-) (otherwise
op))
test-op (loop-case term (:to (loop-case from-key
(:downfrom '>=) (otherwise '<=))) (:below '<) (:downto '>=) (:above '>))
end (eat state)))))
(let ((test (when test-op
(list test-op var (maybe-hoist end state)))))
(push-iter-clause `(,var ,start (,op ,var ,(or by 1)) ,test) state))))
The difference is that test-op is assigned initially nil, and only
re-assigned a value if there is a term. In my example I get infinite loop,
but the same behaviour happens if I have more looping constructs, e.g.
(loop :for i :from 0 :for j :in list :do (print i))
Problem number 2:
Let causes the whole body of loop to be wrapped in function, whereas the
previous version wrapped it in with ({ i : i }) { .... }
Example:
(ps (loop :for i :from 0 :for j :in (array 1 2 3) :do (let ((i i)) (lambda
() i))))
generates
(function () {
var _js207 = [1, 2, 3];
var _js209 = _js207.length;
var FIRST210 = true;
for (var i = 0; true; i += 1) {
(function () {
var _js208 = FIRST210 ? 0 : _js208 + 1;
if (_js208 >= _js209) {
break;
};
var j = _js207[_js208];
var i211 = i;
function () {
return i211;
};
return FIRST210 = null;
})();
};
})();
The diference is that it is illegal to break from a function body, and it
was legal to break from with.
Can somebody help please?
Cheers,
Piotr