[rkward-devel] JS in rkwarddev

meik michalke Meik.Michalke at uni-duesseldorf.de
Wed Oct 28 15:26:22 UTC 2015


hi,

Am Mittwoch, 28. Oktober 2015, 14:54:28 schrieb Thomas Friedrichsmeier:
> meik michalke <Meik.Michalke at uni-duesseldorf.de> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/rkward-devel/attachments/20151028/a95d455f/attachment.sig>


More information about the rkward-devel mailing list