Crafting a Compelling Web Demo


#1

Compiling C codebases to JavaScript is something that has been around a while. The first successful build of Rebol to JavaScript was actually achieved shortly after the Montreal conference.

That was many years ago. So why has it taken so long to get a console in the browser?

Pardon me for repeating myself: the issue is that the browser is rather authoritarian, and while the JavaScript interpreter is running you do not see screen paint events. If you click a button on a JavaScript UI, and there is an associated JavaScript function that runs, if that function takes 10 seconds to run, you will not see any change in the UI until those 10 seconds are over. (There are a few exceptions…like alert boxes or the console log, but that’s not what most people think of when they think of good web design.)

Now enter the Rebol interpreter, written in C. There is a main() function that expects to take control and keep that control until you QUIT. Translate that into JavaScript that’s a function that runs as long as you run the session. Now imagine running that session for 20 minutes.

A program that runs for 20 minutes solid without updating the UI does not sound very satisfying!

Even something as simple as this loop has no opportunity to update the UI, because if paused long enough to give control to the browser to gather input, it would forget which step of the iteration it was on:

loop 100 [
    print "Enter a string:"
    n: input
    print ["You entered:" n]
]

The recent breakthrough was the result of me learning stuff, and even feeding back into the design of emscripten a bit. The implementation is rough, but programs like the above can work…and I believe even more elegant implementations are possible. There’s quite a long way to go, but the mechanic appears solid.

http://hostilefork.com/media/shared/replpad-js/

(Note: I should point out that systems which appear to be doing this generally are not. For instance, if you use repl.it you will realize it is spinning up interpreters on the server side and just echoing it in your browser’s screen–see the Network tab if you are wondering).

So, now what?

Now that a Rebol function can appear to have synchronous side effects, the field is wide-open for what a web application might do.

I’ll pick an example of something I think is kind of “lame”: Rebol’s Logo heritage could be used to do something like a turtle graphics. PEN DOWN, TURN 90, etc.

https://www.calormen.com/jslogo/

It is true that Rebol could be used to show a new spin on this–a PARSE rule that acted on data and the GROUP!s contained reaction code to move the turtle around. But I don’t think it’s new enough. I think the moment you put that turtle up people are going to say “oh, it’s logo” and not be looking for the nuances.

I know Nick of Nick’s Forum has expressed his belief that a Rebol2 GUI equivalent would be compelling. That might lead one to think that wiring up web UI widgets to a view-like dialect and implementing something like the old calculator demo except perhaps like Qooxdoo’s version. I do not feel motivated personally to do that.

So here’s where one has to put on the thinking cap. What can Rebol do in a browser that would be interesting?

This is not a product

I want to be 100% clear in saying that I think Rebol is still very much trapped in the idea stage. It has more questions than it has answers. I would still dissuade most anyone from using these techniques in any kind of serious large scale production. It is an unproven, radical, extremely-odd-to-the-point-of-seeming-careless methodology that makes strange bets. To my tastes it is more an art project than a science project.

So my angle is not how to sell this to people as a product. It’s how to get people interested in the questions it raises. I’d like to see a tutorial that gets people to the meat of what makes Rebol different quickly, that a programming sophisticate could absorb and go “hmmm, I never thought of that”. That’s the audience I want to speak to–not someone who doesn’t know how to write “Hello World” in 5 other languages. Because a beginner has a lot to learn before even starting to think about why someone would do something as “crazy” as Rebol.


#2

If only it has the answer to the top X questions asked. And those are the questions Javascript after all these years still doesn’t have an answer to.