JavaScript & REBOL

After working with both languages a great deal, I’ve come to the realization that JavaScript is the language in common use that’s most akin to REBOL. There’s still a very wide gulf, but there are enough similarities to make it worth a mention. (Not much more than a mention, though.)

At first glance, JavaScript and REBOL don’t look much alike, even when the code is doing the same thing.

// JavaScript
function foo(s) {
 return s + 'foo';
foo: func [s [string!]] [
 rejoin [s "foo"]

We can start to make them look a little more similar if we put the JavaScript inside an object literal and the REBOL inside a block. We’ll also omit the type specifier from the REBOL function, since JavaScript has no equivalent.

 foo: function(s) {
  return s + 'foo';
 foo: func [s] [
  rejoin [s "foo"]

(I should point out that a block and an object literal are not equivalent, but their capabilities overlap a little bit. REBOL’s blocks are much more powerful.)

And that’s about as far as we can go with that. Anyway, it’s not lexical similarity that concerns me here, but functional similarity. For instance, both languages are scripting languages in the sense that they are not (usually) compiled. No big deal there. That’s true of a long list of languages.

However, both languages are prototype languages, and that’s certainly not true of a lot of languages.

function Foo() {
 this.watusi = 3;

function Bar() {
 this.watusi = 4;

Bar.prototype = Foo;

In REBOL, it’s similar, although in my opinion slightly more elegant, even if its syntax looks a bit strange to the curly bracers.

foo: make object! [watusi: 3]
bar: make foo [watusi: 4]

The serialized form of both languages is the language itself. In JavaScript, the JSON format is often used as a way to communicate between client and server. A very similar thing can be done with REBOL, although it has no specific name. (There really isn’t any need to have a special name or notation in REBOL. It’s just REBOL. In fact, being used for messaging is one of the fundamental things REBOL was designed to do.)

{ // JavaScript object literal
 orderno: 37,
 items: [22, 873, 14] // A list of order item numbers

What you see above is exactly what the server would transmit. We’d use it in JavaScript by assigning it to a variable.

var order = getOrder(); // getOrder() returns the object literal specified above

Here’s one REBOL equivalent (of a great many). Here’s what we’d transmit:

orderno: 37
items: [22 873 14]

And here’s how we might use it:

order: get-order
print order/orderno

The reason I didn’t place the REBOL “object literal” inside a block is because it isn’t necessary. When the string is read from the server, the LOAD function will automatically place it inside a block. GET-ORDER would be implemented something like this:

get-order: does [
 make object! load http://localhost:999/foo

In this particular case I tried to make the REBOL look as close to the JavaScript as I could to emphasize their similarities. I would probably implement the above very differently in REBOL under ordinary circumstances, although there’s nothing wrong with how it was done here. Because REBOL has DSLs and the evaluation of blocks is deferred (unlike JavaScript’s object literals), we have quite a few more options.

Another similarity is that both languages allow functions to be passed as arguments.

function callF(f) {

call-f: func [f [any-function!]] [

call-f does [print "called!"]

Both languages are amazingly nimble, although in a flexibility contest REBOL would win easily. It can do everything JavaScript can do and then some. Everything except manipulate the DOM, that is.


  1. Some REBOLers comment here:

  2. Wow amazing article, I have added your blog to my rebol's blog:

    It's a beginner's blog for beginners :)

  3. "However, both languages are prototype languages, and that’s certainly not true of a lot of languages."

    Lua is a lot like JavaScript.

  4. Yes, Lua is an interesting language. I like it. But it's still true that not very many languages are prototype languages.

  5. but what good is this rebol thing ? its not like they can take a generic JW Player

    and HD stream and control that H.264 video content like the JavaScript generating page can from their rebol web one liners or even their pro web server things.

    and even IF they could somehow cobble something together to wrap around the stream H.264 jw-player , it seems the few rebol dev's capable have ZERO Interest in anything remotely graphical or video streaming related judging by the Total lack of any example video scripting apps.

    how many years have they been around ? and not one simple fully working streaming video plug-in or stand alone example to be found, were as every one and his dog knows you want Food embedded HD video on your site, use jw-player and JavaScript.

    didn't their rebol leader and his mate Dave something or other once make the worlds best home video hardware and software OS or something,shame their users cant even bother to write a few working video apps like every one else on the net seems to want to use....

  6. i guess from the masses of reply's then, that rebol's just a page filler for some extra cash, and everyone just continues to use JavaScript to make their real cash ;)

  7. I think you've missed the point, Mr. Anonymous. I'm not comparing REBOL and JavaScript in terms of their market success or employment potential. I'm comparing them syntactically, purely for language enthusiasts. Believe it or not, there are people who like programming languages merely because they are interesting in some way.

    So this isn't about "cash". I know a number of languages with which I can and do make plenty of money: C#, JavaScript, Objective-C, and so on. While I hope that I can one day make money with REBOL, it will never be as a client-side browser scripting language. I like REBOL because I find its syntax interesting. That's it.

  8. oh well that's fine then, in that context yes it seems interesting.

    i thought id go and actually look at what scripts are available as it was today.

    its shame most/many example scripts fail in some nasty way when you open rebol view (any version available) shell window and

    do http:// a direct url to most of the scripts found here though

    i would have thought someone that cared would have fixed that basic problem at some point.

    do http://www.rebol.org/view-script.r?script=area-scroll-style.r

    as just one example, it doest look good when simple example scripts fail, or worse crash the rebol view script interpreter.

    p.s i do like your work, and don't mean to offend if i did.

  9. i came across this while trying to find a simple connect and annonimous chat IRC channel were rebol people might hang out.

    its odd but there isn't one, and you need to register for all the chat options i could find, very odd, but no matter.


    an alpha/beta Compiler from Rebol to JavaScript. — Read more
    some readers might be interested in it here i assume.

  10. : COMPLETELY RENEWED!Party App gives you the complete dutch Party agenda on your iOS device. downloadthefilefast.date From Tag Games: At the end of a hard week have you ever wanted to just let loose and smash some stuff up.

  11. Please note:Paying via InApp-Purchase for the full version is a one-time payment. Visit my site IF YOU LOVE THIS GAME AND WANT TO SEE MORE PLEASE RATE US.

  12. Set the drumming timer for up to infinity and listen in meditation or while performing everyday tasks. download pdf - If you plan to take a taxi and need to figure out how much the price is, we have this function included as well.

  13. Receive high street discounts for regular trackingAWESOME PHOTO COMPARISON TOOLS:- Try on your before photo for size. download software It's easy to view a video in one page while reading an article in the other.