Online Gleam Playground #1109
Replies: 5 comments 23 replies
-
I don't think using import for code evaluation is right for this case. |
Beta Was this translation helpful? Give feedback.
-
We can't use import or eval or anything that the browser provides simply because we don't have access to the internals. But I think I have a plan. Given that the javascript code we're dealing with here is coming from gleam, its going to be simpler than the general case. But I still need some time to figure out how to work with it. |
Beta Was this translation helpful? Give feedback.
-
Wrt const log = window.console.log
window.console.log = function (...messages) {
log(...messages)
messages.forEach(message => {
app.ports.toConsole?.send(...)
})
} This is a snippet for the playground of a language I'm developing. We save a reference to the original |
Beta Was this translation helpful? Give feedback.
-
ok...this is what I've done so far: playground But it has two problems:
|
Beta Was this translation helpful? Give feedback.
-
Sorry to necro this thread, but for posterity: a coworker of mine created a functioning Gleam playground and has it hosted at https://johndoneth.github.io/gleam-playground/ |
Beta Was this translation helpful? Give feedback.
-
One common language feature these days is an online playground. This is a website with a built in text editor where people can try out writing code in the language without having to install anything on their computer. It is useful for getting started with the language, for sharing snippets of code with others for debugging or learning, and they can also be a way of offering interactive tutorials for the language.
I think Gleam would greatly benefit from having something like this.
The upcoming JavaScript generating the backend for the compiler could be the foundation of a playground for Gleam. By two crewing the compiler to web assembly and then emitting JavaScript code we can have the full compilation and execution process happen entirely within the browser, removing the need to host and maintain a system of isolated build machines.
The Glean JavaScript backend emits ES modules, so we cannot use the eval function to evaluate them. This blog post suggests an alternative approach that could be taken with import and data URLs. https://2ality.com/2019/10/eval-via-import.html
A combination of this and some precompiled library modules hosted publicly for import by playground generated modules could be a workable strategy.
Goals
Beta Was this translation helpful? Give feedback.
All reactions