Racketscript: Racket to JavaScript Compiler
github.com
github.com
Great, then we know at least two people know how to read :)
From the README: "RacketScript is an ___experimental____ lightweight Racket to JavaScript"
> https://try.gambitscheme.org/
For some folks who'd like me to trust their web knowledge, having an expired certificate certainly doesn't give me any more trust than I already had.
More on topic: I wonder how the REPL story is with Racketscript? Nothing seems to be mentioned in the README nor in the repository which would make this project a non-starter for the people who got used to ClojureScript and similar efforts.
I think it is great someone is trying to get Racket compiling to Javascript again. I also agree with you about the REPL; while it is interesting to compile Racket to JS, having a REPL, a live environment and all the features of something like ClojureScript has much more utility.
The last part of the demo shows how to use threads in the browser and also the JavaScript FFI. The FFI based on an infix syntax is explained in greater detail in this ELS'21 paper: http://www.iro.umontreal.ca/~feeley/papers/BelangerFeeleyELS... . The paper contains several examples. Here's a simple one you can type at the REPL:
(define message "<h1 id=\"title\">hello!</h1>")
\document.body.insertAdjacentHTML("afterbegin", `message)
\document.getElementById("title").innerText=`(object->string (expt 2 100))
Basically a backslash switches to JavaScript (with infix syntax) and a backquote switches back to Scheme (with prefix syntax).
The whole Gambit system fits in a 640KB gzipped JavaScript file, so it is reasonably fast to load.
If you are interested in a really tiny Scheme implementation in JavaScript that supports tail-calls and call/cc and an incremental Scheme compiler and a REPL and most of the R4RS procedures, you might want to try out the Ribbit Scheme implementation which is just under 6 KB of (non-gzipped) JavaScript: https://udem-dlteam.github.io/ribbit/repl-max.html . That implementation is described in a paper at the VMIL'21 workshop (presentation on October 19).
Tail calls and continuations are more difficult if you want them to be efficient.
Iirc, an interesting bullet-point in their backend rework to make the move to chez meant that doing things like targeting js might be easier now than ever. I would absolutely love a js backend for rkt, it seems like it would be a huge boon to the ecosystem.
One advantage or migrating it to the Chez Scheme version is that some tricky functions (like print or display that have like a million of corner cases) are implemented in Racket or in Chez Scheme, so it's not necessary to write them again in JavaScript.
[1] For example in the old version, only the small chars were interned and in the new version all are interned, so code like (eq? #\λ (integer->char (char->integer #\λ))) may have a different result. It's true in the new version, but in the old version it may be false if the optimizer is not aggressive enough with the constant folding.
Meaning, hopefully, full guile in the browser.
There are quite a few open questions regarding RnRS schemes on webassembly. Currently it seems that the ones available are either discouraged by the limitations of wasm, or are implemented to specifically test non-standard proposals of wasm.
In other words: no fun at all.
There is another schemey language that compiles to JS that accepts things like this:
(when (start-are-aligned?)
(define wtf 5))
wtf ; may or may not be bound.
The ick-factor is high.