Skip to main content
Lion uses Effect Schema throughout the evaluator to validate inputs, discriminate expression shapes at runtime, and produce typed parse errors. Each schema corresponds to a distinct concept in the Lion expression model and is exported from its own subpath so you can import only what you need.

@lionlang/core/schemas/lion-expression

The core expression schemas describe the full range of values a Lion program can contain.
Schema
The top-level union schema. Accepts any value that is a JSON primitive, an array of Lion expressions, or a record with string keys and Lion expression values. This is the schema used by run to validate the expression parameter before evaluation.
Schema
A Schema.Array of recursively-suspended LionExpressionSchema elements. Used by evaluate to detect array expressions and dispatch them to evaluateArray.
Schema
A Schema.Record where:
  • Keys must be non-empty strings (minLength(1)) and must not equal "__proto__".
  • Values are recursively-suspended LionExpressionSchema elements.
Used by evaluate to detect record expressions and dispatch them to evaluateRecord.
type alias
A recursive TypeScript type alias representing the structural form of a Lion expression before schema decoding:
Used as the element type for the lazy Schema.suspend references inside the array and record schemas.

Runtime type checking

Use Schema.is to narrow a value to a specific expression shape at runtime without throwing on failure:

@lionlang/core/schemas/json-primitive

Schema
A union of Schema.String, Schema.Number, Schema.Boolean, and Schema.Null. Represents the leaf values of a Lion expression tree. Numbers, booleans, and null evaluate to themselves; strings are resolved as environment references.

@lionlang/core/schemas/environment

type alias
The union type of ToplevelEnvironment and InnerEnvironment. Both carry a bindingsRef: Ref<Record<string, unknown>> for mutable name storage. InnerEnvironment additionally holds a parent: Environment reference for lexical scope lookup.You do not typically construct Environment values directly — use makeEnvironment from @lionlang/core/evaluation/environment instead.

@lionlang/core/schemas/evaluation

Special form schemas and the callable value schema. Import what you need:
Schema
["eval", LionExpression] — evaluates its argument, then evaluates the result.
Schema
["quote", LionExpression] — returns its argument unevaluated.
Schema
["begin", ...LionExpression[]] — evaluates a sequence of expressions and returns the last value.
Schema
["define", ValidIdentifier, LionExpression] — evaluates the expression and stores it in the global environment under ValidIdentifier. The identifier must be non-empty and cannot be one of the reserved keywords (begin, define, eval, quote, lambda, cond, match) or __proto__.
Schema
["lambda", ValidIdentifier[], LionExpression] — creates a closure over the current scope.
Schema
Union of CondFormWithoutElseSchema and CondFormWithElseSchema:
The else branch is optional. Returns null when no branch matches and no else is present.
Schema
Matches a value against predicate/handler pairs; the last element is a fallback function applied when no pattern matches.
Schema
[LionExpression, ...LionExpression[]] — a non-empty tuple where the head evaluates to a callable. Used as the final catch-all in evaluateArray after all special forms have been checked.
Schema
A declared schema that matches any JavaScript function. Used to validate that the head of a function call expression is actually callable: