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:
The full signature of namespaceEntries is:
The exported stdlib object assembles all eight built-in modules this way:

Importing and using the stdlib

Pass stdlib as the second argument to run:
You can extend stdlib with your own bindings without modifying it:
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.