Arc Forumnew | comments | leaders | submitlogin
3 points by rocketnia 5033 days ago | link | parent

Inspired by http://arclanguage.org/item?id=14938, I've taken a stab at porting Rainbow from Java to JavaScript. Well, maybe it's not so much a matter of inspiration as it is "Hey, I know Java, I know JavaScript, I know Arc, and I use Rainbow. Do I really expect anyone but me to do this?" :-p

At this point, the basic evaluation model is really buggy, mostly thanks to tons of trivial typos. Nevertheless, there's already a REPL where it's possible to accomplish a few basic calculations: http://rocketnia.github.com/rainbow-js/test/

Be careful if you're on a very stringent data regimen, as the REPL page loads the unminified rainbow.js, which is over half a megabyte in size. :-p I'd minify it, but the last time I tried, the minified version was even more broken. (I'm not doing anything special with property name manipulation--I'm actually writing this with the Closure Compiler in mind, just in case--so I think I must have broken the minifier.)

The REPL can't accomplish anything as ambitious as arc.arc... and at this point it can't even accomplish anything as ambitious as 'def! If you're having trouble at the REPL and want to see some expressions that actually work, take a look at rainbow.test.js--which currently has no real tests, just pastes from the REPL.

For further information, take a look at the README. ^_^



2 points by rocketnia 5033 days ago | link

Oh, I should also mention: I've mostly tested this in Chrome. I just tried Firefox, and it mostly accepts the same code, but when there's an error, there seems to be something troublesome about the stack traces. Even an unbound identifier error disrupts the REPL loop and makes it impossible to provide more input.

Opera and IE 8 would be next on my checklist, but at the moment Rainbow.js supports zero platforms, so I might just keep testing on Chrome for a while. :-p

-----

1 point by rocketnia 5029 days ago | link

Rainbow.js can load arc.arc now. ^_^

There's a catch: My reader code is in continuation-passing style, and if the input's too long, it goes into a stack overflow.

Fortunately, the reason it's in CPS is so that it can process the input asynchronously. As long as it's actually working asynchronously, its continuation callbacks occur on fresh event stacks rather than piling up. I could go into more details, but what's important is that for now, submitting the input in smaller pieces is an effective, if ugly, workaround:

  var arcArc = document.getElementsByTagName( "textarea" )[ 0 ].
      value.split( "\n" );
  function readRest() {
      if ( arcArc.length === 0 ) return;
      consoleIn.o.writeString( arcArc.shift() + "\n" );
      setTimeout( readRest, 0 );
  }
  readRest();
For future reference, here's a link to the commit I'm talking about: https://github.com/rocketnia/rainbow-js/commit/60f60282b74e2...

-----

1 point by thaddeus 5029 days ago | link

I must be doing something wrong. I tried entering only 1 line and got:

Message : Unhandled exception on thread#0: Symbol var is not bound....

-----

1 point by rocketnia 5029 days ago | link

I suspect you're entering that JavaScript code at the Arc REPL. ^^; I just pasted that JavaScript here as an excerpt of the full(er) instructions on the REPL page:

"Actually, if you you paste from Java Rainbow's arc.arc source yourself, you'll probably find that Rainbow.js encounters a stack overflow error. At this point it's necessary to enter it in more bite-size pieces. Right now you can accomplish this by pasting all of arc.arc into the input box, then entering the following code into a JavaScript console (not the Arc console!) to have it entered one line at a time:

[the JS code I pasted above]"

In Chrome, the JavaScript console is available under "(wrench icon) > Tools > JavaScript console." On Firefox, I tested it using Firebug's console tab, but I think the Error Console might work too.

Also, pasting the JavaScript snippet all at once should be fine. The point is to enter the Arc code in bite-size pieces, and the JavaScript snippet just automates that process.

I'm considering making this workaround a feature of the REPL interface, as a checkbox or something, but what I'd rather do is fix the issue altogether.

-----

1 point by rocketnia 5027 days ago | link

"what I'd rather do is fix the issue altogether."

Done! Now the reader only uses a number of JavaScript stack frames proportional to the amount of nesting of the program, rather than the number of characters. Feel free to just paste all of arc.arc into the REPL and hit enter. ^_^

I've also tested the REPL on more browsers. The only one that really had a problem was IE 8, and that was because of the code of the REPL interface itself rather than the Rainbow.js runtime. It should work in IE 8 now... except that the performance is terrible there. XD

Any ideas about where this project should go next?

-----

1 point by rocketnia 5018 days ago | link

Rainbow.js is compiling with the Closure Compiler's advanced mode now! The REPL page--which still doesn't load arc.arc--is now down to 146 KB (HTML and JavaScript), rather than over 500.

Furthermore, on most recent browsers, the loading speed seems competitive with, or even better than, the loading speed of Java Rainbow. It might not be a fair comparison, since the contents being loaded are coming through a different kind of input, but I'm still pretty excited. ^_^

-----