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.
import {
  LionExpressionSchema,
  LionArrayExpressionSchema,
  LionRecordExpressionSchema,
} from "@lionlang/core/schemas/lion-expression";
import type { AssumedExpressionType } from "@lionlang/core/schemas/lion-expression";
LionExpressionSchema
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.Union(JsonPrimitiveSchema, LionArrayExpressionSchema, LionRecordExpressionSchema)
LionArrayExpressionSchema
Schema
A Schema.Array of recursively-suspended LionExpressionSchema elements. Used by evaluate to detect array expressions and dispatch them to evaluateArray.
LionRecordExpressionSchema
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.
AssumedExpressionType
type alias
A recursive TypeScript type alias representing the structural form of a Lion expression before schema decoding:
type AssumedExpressionType =
  | JsonPrimitiveType
  | readonly AssumedExpressionType[]
  | { readonly [key: string]: AssumedExpressionType };
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:
import { Schema } from "effect";
import {
  LionExpressionSchema,
  LionArrayExpressionSchema,
  LionRecordExpressionSchema,
} from "@lionlang/core/schemas/lion-expression";

Schema.is(LionExpressionSchema)(value);       // value is LionExpressionType
Schema.is(LionArrayExpressionSchema)(value);  // value is LionArrayExpressionType
Schema.is(LionRecordExpressionSchema)(value); // value is LionRecordExpressionType

@lionlang/core/schemas/json-primitive

import { JsonPrimitiveSchema } from "@lionlang/core/schemas/json-primitive";
import type { JsonPrimitiveType } from "@lionlang/core/schemas/json-primitive";
JsonPrimitiveSchema
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

import type { Environment } from "@lionlang/core/schemas/environment";
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:
import {
  BeginFormSchema,
  CondFormSchema,
  DefineFormSchema,
  EvalFormSchema,
  FunctionCallFormSchema,
  LambdaFormSchema,
  MatchFormSchema,
  QuoteFormSchema,
  LionFunctionValueSchema,
} from "@lionlang/core/schemas/evaluation";
EvalFormSchema
Schema
["eval", LionExpression] — evaluates its argument, then evaluates the result.
QuoteFormSchema
Schema
["quote", LionExpression] — returns its argument unevaluated.
BeginFormSchema
Schema
["begin", ...LionExpression[]] — evaluates a sequence of expressions and returns the last value.
DefineFormSchema
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__.
LambdaFormSchema
Schema
["lambda", ValidIdentifier[], LionExpression] — creates a closure over the current scope.
CondFormSchema
Schema
Union of CondFormWithoutElseSchema and CondFormWithElseSchema:
["cond", [predicate, result], ..., ["else", result]]
The else branch is optional. Returns null when no branch matches and no else is present.
MatchFormSchema
Schema
["match", value, [predicate, handler], ..., fallback-fn]
Matches a value against predicate/handler pairs; the last element is a fallback function applied when no pattern matches.
FunctionCallFormSchema
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.
LionFunctionValueSchema
Schema
A declared schema that matches any JavaScript function. Used to validate that the head of a function call expression is actually callable:
export type LionFunctionValueType = (...args: unknown[]) => EvaluateResult;