Skip to main content
Lion ships a standard library that covers the most common operations you need when writing programs in JSON Lisp. Every function in the stdlib is namespaced under its module name, so number/add lives in the number module and array/map lives in the array module. This convention keeps names unambiguous and makes it easy to see at a glance which module a call belongs to.

How the stdlib is structured

Each module is a plain JavaScript object whose keys become the right-hand side of the namespace. The namespaceEntries utility prefixes every key with the module name:
import { namespaceEntries } from "@lionlang/core/modules";

const myModule = {
  double: (n: number) => n * 2,
};

const env = namespaceEntries("myModule", myModule);
// => { "myModule/double": [Function] }
The full signature of namespaceEntries is:
const namespaceEntries = (
  namespace: string,
  record: Record<string, unknown>
) => Record<string, unknown>
The exported stdlib object assembles all eight built-in modules this way:
import { stdlib } from "@lionlang/core/modules";
// stdlib contains: number/add, string/concat, array/map, ...

Importing and using the stdlib

Pass stdlib as the second argument to run:
import { Effect } from "effect";
import { run } from "@lionlang/core/evaluation/evaluate";
import { stdlib } from "@lionlang/core/modules";

const result = await Effect.runPromise(
  run(["number/add", 1, 2], stdlib)
);
// => 3
You can extend stdlib with your own bindings without modifying it:
const env = {
  ...stdlib,
  PI: Math.PI,
  greet: (name: string) => `Hello, ${name}!`,
};

await Effect.runPromise(run(["greet", "world"], env));
// => "Hello, world!"
Every stdlib entry resolves as a string reference in a Lion expression. Because strings look up the environment first, "number/add" in a Lion array becomes the add function from the number module.

Modules

number

Arithmetic operations and numeric comparisons: add, subtract, multiply, divide, equals?, lessThan, greaterThan, and more.

string

Text operations including equals?, length, concat, startsWith, endsWith, includes, and indexOf.

boolean

Logical operations: not, and, or, xor, nand, nor, and equals? for boolean values.

array

List operations: make, head, tail, length, concat, includes?, map, flat-map, and reduce.

object

JavaScript object interop: get, get-path, json-stringify, keys, values, new, get-method, call-method, and path variants.

func

Function utilities: bind, apply, callback for Lion-to-JS interop, and partial for partial application.

value

Type predicates: function?, number?, string?, boolean?, object?, array?, null?, and the identity passthrough.

console

Logging helpers: log prints a message, log-json pretty-prints any value as JSON.