hi, Am Mittwoch, 28. Oktober 2015, 14:54:28 schrieb Thomas Friedrichsmeier: > meik michalke <[email protected]> wrote: > > i could use a typical use case you have in mind, to optimize this bit. > > I was mostly being curious, if you had an idea on this, since, of > course in this example, the syntactic differences are much larger.
ah, i see. well, yes, this was a bit harder to solve because of the
differences. however, if someone evaluated the existing JS code files for
commonly used language constructs or functions in JS for plugins, i think we
could make pretty much of that work with rkwarddev now.
> Still I suppose your solution should do the trick, esp. considering
> that for-loops won't be needed too often (outside optionsets, at least).
btw, i just discovered two issues: vectors resulted in just a blob of garbage,
they are now collapsed with commas.
more importantly, you cannot simply use the iterator variable in the loop
body, it will give you an "object not found" error when js() tries to make
sense of the code. i tried to solve this inside the function, but i didn't
manage. but i found a workaround and added that to the docs:
i <- substitute(i) # the workaround...
cat(rk.paste.JS(js(
for (i in 1:10) {
echo(i)
}
)))
> Regarding the var names, I'd suggest to use a prefix + counter, instead
> of pure randomness. Then at least the var names will make a tiny bit of
> sense, if somebody is trying to read them. E.g. "_RKD_for_array_1" and
> "_RKD_for_index_1", or something like that.
but what happens if someone decides to use two nested for loops, wouldn't the
second overwrite the variables?
at least, the generated code has a comment explaining the weird names:
// the variable names "a1QWFJ" and "icdgKX" were randomly generated
var a1QWFJ = new Array();
a1QWFJ.push(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
for (var i=a1QWFJ[0], icdgKX=0; icdgKX < a1QWFJ.length; icdgKX++,
i=a1QWFJ[icdgKX]) {
echo(i);
}
i admit it's kind of hard to read, allthough it pretty much only ever affects
the actual "for" conditional statement, not the loop body.
viele grüße :: m.eik
--
dipl. psych. meik michalke
institut f"ur experimentelle psychologie
abt. f"ur diagnostik und differentielle psychologie
heinrich-heine-universit"at d-40204 d"usseldorf
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ rkward-devel mailing list [email protected] https://mail.kde.org/mailman/listinfo/rkward-devel
