Racket is a huge language, so be patient wrt features.
To keep motivation high I decided to implement a subset that
can be used to built practical applications - and then extend
the supported features from there. Hopefully, this strategy
will also lead to some early adopters that can help me
prioritize which features to add.
Some features are simply "more of the same".
In this category falls more types of hash tables.
Supporting bignums are also a matter of just doing it.
Other features require more work. I have already done
some work on implementing modules in terms of linklets.
When linklets/modules work, we can reuse the existing
implementation of regular expressions.
Adding continuation marks and delimited continuations
require adding a CPS-pass. This is certainly doable.
Postponing it has been great though. Having a direct style
compiler means the generated code follows the structure
in the input source code. And that makes debugging easier.
Now that bugs have become rarer, it makes sense to look at CPS.
I read the WASM spec and became somewhat of an expert in it for the purpose of eventually designing a low-level language specifically for wasm, to be the most efficient and lowest-level language you could possibly have for wasm, and then gradually add high level concepts into it to make it more convenient. Kind of like building C on top of asm, and then gradually evolving it into C++. That project never came about though due to lack of community interest and time on my part, but I like seeing languages that take a fresh look at how to integrate with wasm using novel techniques to aim for maximal efficiency.
I'm working on something like this right now, targeting WASM GC. I started with functions, basic numeric types, arrays, and structs. Then added blocks, control flow, and strings. Then interfaces, mixins, classes, and extension classes. It's now something like a statically typed mashup of TypeScript, Swift, and Dart, all done in the best way I could figure out specifically for WASM GC.
It's been a really fun side project.
I do think there is a market for something like this - optimizing an existing language for WASM, or ephemeral networked code delivery in general, can be really hard. And a statically typed, WASM-oriented, very familiar high-level language, that can give very good static errors, and quickly run in a secure sandbox might be a good target for LLM-generated code.
I had the exact same idea around 5 years ago, and actually built a language. But without a stdlib it’s a bit useless and as there was no component model at the time it was impossible to have one.
> to be the most efficient and lowest-level language you could possibly have for wasm, and then gradually add high level concepts into it to make it more convenient. Kind of like building C on top of asm, and then gradually evolving it into C++. That project never came about though due to lack of community interest and time on my part, but I like seeing languages that take a fresh look at how to integrate with wasm using novel techniques to aim for maximal efficiency.
I wonder how much efficient would such wasm be compared to native itself theoretically?
I really like libriscv as well, what are your thoughts on libriscv and now the recent project created by legendary fwsgonzo about looongarch.
Although I would say that libriscv/loongarch are more focused on trying to start the fastest as much as possible instead of pure performance (for which if atleast for the purpose of sandboxing, fwsgonzo has also created tinykvm which is really quite close to native performance)
Whalesong used the built-in bytecode compiler and compiled the bytecode to JavaScript. Reusing the bytecode compiler is in principle a good idea - but each time the bytecodes are changed, Whalesong needs to be updated.
And after the move to Chez Scheme as backend, the bytecode compiler is no longer a part of the main compilation path.
JVM languages always target bytecode because it’s much simpler and stable than Java as a language. It almost never changes and when it does it normally won’t break code generation since it’s only adding type system information, for example, as with records.
Speaking of prolific Racketeers... Noel! Just an hour ago, on a walk, I was thinking, "I should work through that one LLM book, and implement it in Racket." (But have started job-hunting, so will probably be Python.)
I've got so much other stuff I'd rather learn and code I'd rather write (C/wasm backend for my language), but I've also started job hunting and probably should understand how this latest fad works. Neural networks have long been on my todo list anyway.
It is interesting to see another language target WebAssembly especially one like Racket. The fact that it compiles to a subset of the language limits its utility right now. I think it is a neat proof of concept but it needs full language support.
For folks curious about the supported language subset, here's a summary:
- Modules aren't implemented yet, but are high on the list
- Continuation-based control flow isn't supported yet, including break and promises. Tail calls are supported though.
- No support for complex numbers, bignums, weak hashtables, immutable hashtables, prefab structs, regexp, or file I/O support
Most of the rest of racket/base should work, according to the README. There's also a FFI for javascript, including bindings for Math, DOM, Canvas, MathJax, XTermJS, and JSXGraph. Overall feels like you can use most of the language right now unless you need odd Racket-isms or call/cc.
I don't know that there are any similaries besides the names -- well maybe something thematic about distributing the future or what looked like it at the time to more programmers -- but the handful of times I've run across Grain (probably all on HN) I'm reminded of Wheat https://web.archive.org/web/20050215032130/http://wheatfarm....
I wouldn't say compiling full Racket to WebAssembly is impossible.
But I think the consensus is that one can't add a WebAssembly backend to the compiler in the same manner as the x86 and arm backends. These backends manipulate the stack in ways WebAssembly prohibits.
This forces an Racket implementation to make continuations explicit.
And that will most likely mean a WebAssembly backend will be slower than the native backends.
You could probably model continuations using the wasm GC feature since you can then pass around function references and strongly typed continuation objects, but making it work certainly wouldn't be trivial.
Hi All,
It's still early days for the WebRacket project.
Racket is a huge language, so be patient wrt features.
To keep motivation high I decided to implement a subset that can be used to built practical applications - and then extend the supported features from there. Hopefully, this strategy will also lead to some early adopters that can help me prioritize which features to add.
Some features are simply "more of the same". In this category falls more types of hash tables. Supporting bignums are also a matter of just doing it.
Other features require more work. I have already done some work on implementing modules in terms of linklets. When linklets/modules work, we can reuse the existing implementation of regular expressions.
Adding continuation marks and delimited continuations require adding a CPS-pass. This is certainly doable. Postponing it has been great though. Having a direct style compiler means the generated code follows the structure in the input source code. And that makes debugging easier. Now that bugs have become rarer, it makes sense to look at CPS.
Enjoy.
/Jens Axel
Are there any architectural similarities or crossover with Hoot (Guile Scheme -> Wasm) or are you taking a completely different approach?
I read the WASM spec and became somewhat of an expert in it for the purpose of eventually designing a low-level language specifically for wasm, to be the most efficient and lowest-level language you could possibly have for wasm, and then gradually add high level concepts into it to make it more convenient. Kind of like building C on top of asm, and then gradually evolving it into C++. That project never came about though due to lack of community interest and time on my part, but I like seeing languages that take a fresh look at how to integrate with wasm using novel techniques to aim for maximal efficiency.
I'm working on something like this right now, targeting WASM GC. I started with functions, basic numeric types, arrays, and structs. Then added blocks, control flow, and strings. Then interfaces, mixins, classes, and extension classes. It's now something like a statically typed mashup of TypeScript, Swift, and Dart, all done in the best way I could figure out specifically for WASM GC.
It's been a really fun side project.
I do think there is a market for something like this - optimizing an existing language for WASM, or ephemeral networked code delivery in general, can be really hard. And a statically typed, WASM-oriented, very familiar high-level language, that can give very good static errors, and quickly run in a secure sandbox might be a good target for LLM-generated code.
I had the exact same idea around 5 years ago, and actually built a language. But without a stdlib it’s a bit useless and as there was no component model at the time it was impossible to have one.
> to be the most efficient and lowest-level language you could possibly have for wasm, and then gradually add high level concepts into it to make it more convenient. Kind of like building C on top of asm, and then gradually evolving it into C++. That project never came about though due to lack of community interest and time on my part, but I like seeing languages that take a fresh look at how to integrate with wasm using novel techniques to aim for maximal efficiency.
I wonder how much efficient would such wasm be compared to native itself theoretically?
I really like libriscv as well, what are your thoughts on libriscv and now the recent project created by legendary fwsgonzo about looongarch.
Although I would say that libriscv/loongarch are more focused on trying to start the fastest as much as possible instead of pure performance (for which if atleast for the purpose of sandboxing, fwsgonzo has also created tinykvm which is really quite close to native performance)
A SIMD ECS language would probably be that today and be more modern than C.
Is there any shared lineage between this and Whalesong, a previous Racket->JS compiler?
Of course both projects have the same maintainer if I recall, Jens Axel Søgaard is a rockstar :)
No, there is nothing in common with Whalesong.
Whalesong used the built-in bytecode compiler and compiled the bytecode to JavaScript. Reusing the bytecode compiler is in principle a good idea - but each time the bytecodes are changed, Whalesong needs to be updated.
And after the move to Chez Scheme as backend, the bytecode compiler is no longer a part of the main compilation path.
JVM languages always target bytecode because it’s much simpler and stable than Java as a language. It almost never changes and when it does it normally won’t break code generation since it’s only adding type system information, for example, as with records.
Is Racket bytecode different?
Jens Axel Søgaard is cool and involved in many things. We collaborated on SICP support.
Original developer of Whalesong was Danny Yoo. https://www.hashcollision.org/whalesong/
There was also this: https://docs.racket-lang.org/racketscript/
Dave Herman worked on various JS-related libraries for Racket (or PLT Scheme) before he was involved with Rust.
ah that's right! apologies
I love this. Racket is the future we were promised.
Speaking of prolific Racketeers... Noel! Just an hour ago, on a walk, I was thinking, "I should work through that one LLM book, and implement it in Racket." (But have started job-hunting, so will probably be Python.)
Which one LLM book?
I've got so much other stuff I'd rather learn and code I'd rather write (C/wasm backend for my language), but I've also started job hunting and probably should understand how this latest fad works. Neural networks have long been on my todo list anyway.
Hoot is another interesting one: https://spritely.institute/hoot/
I noticed the --expose-gc. Does this mean it's using the (now standardized) Wasm GC feature?
It is interesting to see another language target WebAssembly especially one like Racket. The fact that it compiles to a subset of the language limits its utility right now. I think it is a neat proof of concept but it needs full language support.
For folks curious about the supported language subset, here's a summary:
- Modules aren't implemented yet, but are high on the list
- Continuation-based control flow isn't supported yet, including break and promises. Tail calls are supported though.
- No support for complex numbers, bignums, weak hashtables, immutable hashtables, prefab structs, regexp, or file I/O support
Most of the rest of racket/base should work, according to the README. There's also a FFI for javascript, including bindings for Math, DOM, Canvas, MathJax, XTermJS, and JSXGraph. Overall feels like you can use most of the language right now unless you need odd Racket-isms or call/cc.
check out grain! https://grain-lang.org/
I don't know that there are any similaries besides the names -- well maybe something thematic about distributing the future or what looked like it at the time to more programmers -- but the handful of times I've run across Grain (probably all on HN) I'm reminded of Wheat https://web.archive.org/web/20050215032130/http://wheatfarm....
As far as I know compiling full Racket to WASM is impossible because of continuations.
I wouldn't say compiling full Racket to WebAssembly is impossible. But I think the consensus is that one can't add a WebAssembly backend to the compiler in the same manner as the x86 and arm backends. These backends manipulate the stack in ways WebAssembly prohibits.
This forces an Racket implementation to make continuations explicit. And that will most likely mean a WebAssembly backend will be slower than the native backends.
You could probably model continuations using the wasm GC feature since you can then pass around function references and strongly typed continuation objects, but making it work certainly wouldn't be trivial.
Is a (Web)Racket engineer a racketeer?
They're certainly a schemer. :-)