Janet is a lightweight, embeddable, Lisp-like (Clojure-like), dynamically
typed programming language.
In LiveCodes, Janet runs in the browser on the Janet interpreter compiled to WebAssembly, entirely
client-side. No server is involved.
Usage
Demo:
show code
- JS
- TS
- React
- Vue
- Svelte
- Solid
- Preact
- Web Components
import { createPlayground } from 'livecodes';
const options = {
"config": {
"activeEditor": "script",
"script": {
"language": "janet-wasm",
"content": "(print \"Hello, World!\")"
},
"mode": "simple",
"editor": "auto",
"tools": {
"status": "full"
}
}
};
createPlayground('#container', options);
import { createPlayground, type EmbedOptions } from 'livecodes';
const options: EmbedOptions = {
"config": {
"activeEditor": "script",
"script": {
"language": "janet-wasm",
"content": "(print \"Hello, World!\")"
},
"mode": "simple",
"editor": "auto",
"tools": {
"status": "full"
}
}
};
createPlayground('#container', options);
import LiveCodes from 'livecodes/react';
export default function App() {
const options = {
"config": {
"activeEditor": "script",
"script": {
"language": "janet-wasm",
"content": "(print \"Hello, World!\")"
},
"mode": "simple",
"editor": "auto",
"tools": {
"status": "full"
}
}
};
return (<LiveCodes {...options} />);
}
<script setup>
import LiveCodes from "livecodes/vue";
const options = {
"config": {
"activeEditor": "script",
"script": {
"language": "janet-wasm",
"content": "(print \"Hello, World!\")"
},
"mode": "simple",
"editor": "auto",
"tools": {
"status": "full"
}
}
};
</script>
<template>
<LiveCodes v-bind="options" />
</template>
<script>
import LiveCodes from 'livecodes/svelte';
const options = {
"config": {
"activeEditor": "script",
"script": {
"language": "janet-wasm",
"content": "(print \"Hello, World!\")"
},
"mode": "simple",
"editor": "auto",
"tools": {
"status": "full"
}
}
};
</script>
<LiveCodes {...options} />
import LiveCodes from 'livecodes/solid';
export default function App() {
const options = {
"config": {
"activeEditor": "script",
"script": {
"language": "janet-wasm",
"content": "(print \"Hello, World!\")"
},
"mode": "simple",
"editor": "auto",
"tools": {
"status": "full"
}
}
};
return (<LiveCodes {...options} />);
}
import LiveCodes from 'livecodes/preact';
export default function App() {
const options = {
"config": {
"activeEditor": "script",
"script": {
"language": "janet-wasm",
"content": "(print \"Hello, World!\")"
},
"mode": "simple",
"editor": "auto",
"tools": {
"status": "full"
}
}
};
return (<LiveCodes {...options} />);
}
<live-codes></live-codes>
<script type="module">
import "livecodes/web-components";
const playground = document.querySelector("live-codes");
playground.config = {
"activeEditor": "script",
"script": {
"language": "janet-wasm",
"content": "(print \"Hello, World!\")"
},
"mode": "simple",
"editor": "auto",
"tools": {
"status": "full"
}
};
</script>
Standard I/O
The program runs on the result page. Anything it prints is captured and
shown in the console. Standard input is passed by setting the
livecodes.janetWasm.input property in JavaScript before the program runs. It is read in Janet with
(file/read stdin :all) and friends; a program that never reads never notices it was there. To run
again with new input, call livecodes.janetWasm.run(input).
Communication with JavaScript
A few helper properties and methods are available in the browser global livecodes.janetWasm
object:
livecodes.janetWasm.input: the standard input passed to the program.
livecodes.janetWasm.loaded: a promise that resolves when the interpreter has downloaded and the
program has run once. It rejects if the runtime fails to load. Other helpers should be used after
it resolves.
livecodes.janetWasm.output: the program's output, standard output and standard error in the
order the program wrote them.
livecodes.janetWasm.error: the interpreter diagnostics, if the program failed.
livecodes.janetWasm.exitCode: the exit code of the program (0 ok, 1 runtime error, 2
compile error, 4 parse error).
livecodes.janetWasm.run(input): runs the code again with new input, returning a promise that
resolves to { output, error, exitCode }.
Example:
show code
- JS
- TS
- React
- Vue
- Svelte
- Solid
- Preact
- Web Components
import { createPlayground } from 'livecodes';
const options = {
"template": "janet-wasm",
"params": {
"activeEditor": "markup"
}
};
createPlayground('#container', options);
import { createPlayground, type EmbedOptions } from 'livecodes';
const options: EmbedOptions = {
"template": "janet-wasm",
"params": {
"activeEditor": "markup"
}
};
createPlayground('#container', options);
import LiveCodes from 'livecodes/react';
export default function App() {
const options = {
"template": "janet-wasm",
"params": {
"activeEditor": "markup"
}
};
return (<LiveCodes {...options} />);
}
<script setup>
import LiveCodes from "livecodes/vue";
const options = {
"template": "janet-wasm",
"params": {
"activeEditor": "markup"
}
};
</script>
<template>
<LiveCodes v-bind="options" />
</template>
<script>
import LiveCodes from 'livecodes/svelte';
const options = {
"template": "janet-wasm",
"params": {
"activeEditor": "markup"
}
};
</script>
<LiveCodes {...options} />
import LiveCodes from 'livecodes/solid';
export default function App() {
const options = {
"template": "janet-wasm",
"params": {
"activeEditor": "markup"
}
};
return (<LiveCodes {...options} />);
}
import LiveCodes from 'livecodes/preact';
export default function App() {
const options = {
"template": "janet-wasm",
"params": {
"activeEditor": "markup"
}
};
return (<LiveCodes {...options} />);
}
<live-codes
template="janet-wasm"></live-codes>
<script type="module">
import "livecodes/web-components";
const playground = document.querySelector("live-codes");
playground.params = {
"activeEditor": "markup"
};
</script>
Language Info
Name
janet-wasm
Aliases / Extensions
janet, wasm.janet
Editor
script
Compiler
The Janet interpreter compiled to WebAssembly (built with Emscripten), packaged by
@live-codes/janet-wasm.
Version
Janet 1.42.1.
Not currently supported.
Live Reload
By default, new code changes are sent to the result page for re-evaluation without a full page
reload, avoiding the need to reload the interpreter. This behavior can be disabled by adding the code
comment # __livecodes_reload__ to the Janet code, which forces a full page reload.
This comment can be added in the hiddenContent property of the editor for embedded playgrounds.
Example Usage
(defn fib [n]
(if (< n 2)
n
(+ (fib (- n 1)) (fib (- n 2)))))
(each n (range 10)
(prin (fib n) " "))
(print)
Each run is independent: definitions from one run do not survive into the next.
Starter Template
https://livecodes.io/?template=janet-wasm
Links