Arc Forumnew | comments | leaders | submitlogin
A working Arc in Javascript?
3 points by lark 1516 days ago | 14 comments
Aside from Rainbow.js, which has a different goal and is ~20,000 lines of code, does anyone know of or feels like writing a short Arc repl in Javascript?

6 points by rocketnia 1516 days ago | link

This might be exactly what you're looking for:

The creator (smihica, Shin Aoyama) hasn't come to the forum yet, but their work is impressive. Just look at that REPL start up in under a second! On my machine anyway. :)

Thanks to svetlyak40wt for discovering this project 80 days ago ( It was in active development then, and it's still active now.


The primary spark that led me to make Rainbow.js was a desire to respond constructively to threads like this one.

Using Rainbow was a side effect because I wanted to wow people with the execution speed, which conanite had already meticulously worked on in Rainbow. This was still tied into the desire to help those forum threads along: Between speed and portability, what possible excuse could there be not to use it? ^_^

Once I committed to particular technical goals involving consistency with Rainbow, the 20,000 lines of code were basically predetermined. It's kind of unfortunate that it would fail to be helpful in threads like this one, but it's not all a loss.

The secondary spark that led me to make Rainbow.js was that I wanted to get the hang of using JavaScript, after having worked mostly in Arc for a few years. That goal was met. :)


3 points by lark 1515 days ago | link

Thank you so much for this!! arc-js looks great. I'm able to define and run Arc macros with it.

This changes everything. With arc-js you can start writing client-side apps in the browser without dealing with Javascript. You can add libraries in arc-js that do that (are there any already?) The big advantage is you bypass HTML: you can make a browser and a server send sexps back and forth.

There I was thinking there was no hope with an Arc in Javascript and sure enough Arc is quietly thriving.


2 points by shader 1514 days ago | link

That arc-js looks very promising, though also somewhat incompatible with the existing libraries.

For instance, the basic fizzbuzz example provided on the main page looks very similar, but doesn't actually run in anarki. Maybe that's anarki's fault, but the syntax of the for loop is different.

I do like the idea of arc ported to js though; makes getting access to mongodb easier, at the very least :)


2 points by akkartik 1514 days ago | link

That's my fault, I'm afraid. I changed anarki's for to up: (backstory:;

In general, worrying about compatibility in the arc/anarki neighborhood is a fool's errand. Not worth doing. Just do what makes sense, and don't be afraid to be different.


1 point by shader 1513 days ago | link


In this particular case it would be nice to have consistency on both ends. Though I guess the best way to achieve that is probably with node.


3 points by Mitranim 1514 days ago | link

Thanks for sharing, rocketnia! I’ve been looking into ways of getting started, and Arc.js looks like the most novice-friendly implementation so far. Node.js and browser is what I use for hobby coding anyway. :)


2 points by shader 1516 days ago | link

I haven't gotten that far yet, but I was thinking it would be neat to hack something on top of wat.js until it could support arc.arc. It may not be the right way to create a fully compatible arc implementation, but it is certainly one of the smaller bases to build a javascript based lisp on. It also has a lot of the fundamental language features I wish arc had, like first class environments and fexprs, right out of the box.

The only drawback would be speed; a more directly compiled lisp would probably have better performance.


2 points by lark 1516 days ago | link

When I looked at wat.js it didn't have macros. That was a bigger drawback than speed, because then you can't generate any HTML. An Arc in Javascript could get away with implementing less, like ignoring continuations and garbage collection.


2 points by shader 1516 days ago | link

I'm pretty sure it has macros. Even if it didn't, their effects are easily duplicated with fexprs.

Rather, a macro can be described as an extension of the compiler, while a fexpr is an extension of the interpreter. In a compiled language, macros can be an optimization tool, because they can perform arbitrary computation at compile time.

In wat.js, which I believe is interpreted, macros provide relatively little value. They can still perform slightly better, because they only need to be expanded once. To quote directly from manuel:

"To fexprs I also add macros. When a macro is used as the operator of a form, the form's code gets changed to the macro's output when the macro is first called, a technique I learned from here. I like macros because they make syntactic abstraction cost-free - with fexprs alone there is always an interpretative overhead. Still, Wat macros, like fexprs, do not work with quoted identifiers, but with first-class values, so many hygiene problems are avoided."

So generating HTML with the same kind of dsl that arc uses should be fairly painless. Either that, or I misunderstood what you were saying entirely.


1 point by lark 1516 days ago | link

I must have missed the macros then. The biggest problem I had with wat-js is that... I couldn't figure out how to run it. I wish it had a single shell script that you ran and brought up a repl. So one doesn't have to spent time copy-pasting stuff from a text file into an html file and firing up a browser, or typing their code within double quotes or doing anything else.

Yes I was talking about


2 points by akkartik 1516 days ago | link

wat-js seems to have some instructions in the readme. Did you try them?


2 points by lark 1515 days ago | link

I tried them now and was able to get up a Wat VM. But I haven't been able to figure out how to run macros in there.

I wish there were examples. Snippets you can copy paste that do lots of useful stuff like It shouldn't take anyone more than 10secs to find how to do things. It's disheartening to hear such good work remains unused only because there are no examples but I suspect it's the truth. That's what happened to me.

Language designers think some cool esoteric feature is the killer feature of a language but a more useful feature might be examples: an implementation of an application developers want, like Arc did by providing a webserver and a blog.arc. If you are writing a language, ship a useful app with it, like C did with UNIX.


3 points by shader 1515 days ago | link

I would look at the boot.js file. It's kind of like arc.arc is for arc, in that it is a lisp-based bootstrap of all of the basic functions made available in the default environment.

It should give you basic examples of how to write code in wat, as well as show you which functions are defined. Of course, most of them don't actually have examples in the file, as it's merely defining the standard library, but it's a start. There's also test.wat, and the authors blog: (which unfortunately mostly uses the underlying json representation for most of its code).

And the 'killer feature' of wat.js is not that it has first class environments or fexpr, which are admittedly very cool, but that the core language implementation that supports all of these and more is only a few hundred lines of code. There's more in the repository of course, but all of that is to provide the standard library or add sexpression parsing, etc. This makes wat a very good minimal platform for building a custom language.


1 point by akkartik 1516 days ago | link

Are you talking about or something else?