Roselisp

raw JSON →
0.0.1 verified Fri May 01 auth: no javascript

Scheme-like Lisp interpreter and transpiler to JavaScript, self-hosted, also provides decompilation from JS to Lisp. Current version 0.0.1 (early development). Key differentiators: supports both interpretation and compilation to JavaScript, includes decompilation, self-hosted, MPL-2.0 licensed unlike many Lisp implementations. Useful for embedding Lisp in JS projects or learning compiler construction.

error Error: Cannot find module 'roselisp'
cause Package not installed or not in node_modules
fix
Run npm install roselisp in your project.
error TypeError: roselisp.interpret is not a function
cause Using default import incorrectly; API uses named exports interpret/compile
fix
Use import { interpret } from 'roselisp' instead.
error SyntaxError: Unexpected token 'export'
cause Using CommonJS require() with an ESM-only package
fix
Use import syntax or enable ESM in package.json: "type": "module".
breaking ESM-only: package does not support CommonJS require()
fix Use 'import' syntax instead of 'require()'.
deprecated Global install may require sudo on Unix systems
fix Use `npm install -g roselisp` with appropriate permissions or use npx.
gotcha API may change drastically as version is 0.0.1 (unstable).
fix Pin exact version or expect breaking changes.
gotcha Decompilation is imperfect; only works for JS that matches patterns emitted by compiler.
fix Use decompile only on JS generated by roselisp's compiler.
gotcha Interpreted code runs in a sandboxed environment; no direct Node.js I/O access.
fix Use JavaScript for I/O, pass data to Lisp via bindings.
npm install roselisp
yarn add roselisp
pnpm add roselisp

Imports Roselisp, interprets a Lisp definition, compiles to JS, and decompiles JS back to Lisp using named exports.

import roselisp from 'roselisp';

const code = `(define (hello) (display "Hello from Roselisp!"))`;
const result = roselisp.interpret(code);
console.log(result); // outputs hello function definition

// Compile to JavaScript
const jsCode = roselisp.compile(code);
console.log(jsCode); // outputs JS representation

// Decompile JavaScript to Lisp (if structured)
const lispCode = roselisp.decompile('function hello() { console.log("Hello from Roselisp!"); }');
console.log(lispCode);