glisp / build
build
Variables
astType
constastType:SymAST
Defined in: build.ts:234
The ast type — type of quoted forms / macro inputs and outputs.
booleanType
constbooleanType:SymAST
Defined in: build.ts:226
The boolean type.
bottomType
constbottomType:SymAST
Defined in: build.ts:232
The ! (bottom) type.
g
constg:object
Defined in: build.ts:264
The g namespace bundles all builders. Equivalent to importing each function by name; some hosts prefer the namespaced form (g.lit(...)) per the spec.
Type Declaration
| Name | Type | Default value |
|---|---|---|
access() | (target, key) => AccessAST | - |
ast | SymAST | astType |
boolean | SymAST | booleanType |
bottom | SymAST | bottomType |
call() | (head, …args) => CallAST | - |
callKw() | (head, args, kwargs) => CallAST | - |
enum() | (…values) => CallAST | enumType |
fn() | (params, returnType) => FnAST | - |
host() | (value) => HostAST | - |
let() | (bindings, body) => LetAST | letBlock |
lit() | (value) => LitAST | - |
meta() | (content, expr) => MetaAST | - |
number | SymAST | numberType |
path() | (…segments) => PathAST | - |
print() | (ast) => string | - |
quote() | (expr) => QuoteAST | - |
record() | (fields) => RecordAST | - |
splice() | (expr) => SpliceAST | - |
spread() | (expr) => SpreadAST | - |
string | SymAST | stringType |
sym() | (name) => SymAST | - |
top | SymAST | topType |
unit | SymAST | unitType |
unquote() | (expr) => UnquoteAST | - |
vec() | (…elements) => VecAST | - |
vector() | (T) => VecAST | vectorType |
numberType
constnumberType:SymAST
Defined in: build.ts:222
The number type.
stringType
conststringType:SymAST
Defined in: build.ts:224
The string type.
topType
consttopType:SymAST
Defined in: build.ts:230
The _ (top) type.
unitType
constunitType:SymAST
Defined in: build.ts:228
The unit type.
Functions
access()
access(
target,key):AccessAST
Defined in: build.ts:80
Accessor sugar: target.key. Equivalent in meaning to Call(target, [Lit(key)]).
Parameters
| Parameter | Type |
|---|---|
target | AST |
key | string | number |
Returns
call()
call(
head, …args):CallAST
Defined in: build.ts:64
Application: (head a b ...).
Parameters
| Parameter | Type |
|---|---|
head | AST |
…args | readonly AST[] |
Returns
callKw()
callKw(
head,args,kwargs):CallAST
Defined in: build.ts:71
Application with keyword arguments: (head a b k1=v1 k2=v2).
Parameters
| Parameter | Type |
|---|---|
head | AST |
args | readonly AST[] |
kwargs | Readonly<Record<string, AST>> |
Returns
enumType()
enumType(…
values):CallAST
Defined in: build.ts:250
Parameters
| Parameter | Type |
|---|---|
…values | readonly (string | number | boolean)[] |
Returns
fn()
fn(
params,returnType):FnAST
Defined in: build.ts:147
Function literal / function-type AST.
Always returns a plain FnAST (with body = null — i.e. a function-type expression). Chain .withBody(expr) and/or .withGenerics(...) on the result to add a body and generic parameters; both produce a new FnAST.
fn({a: g.number, b: g.number}, g.number) // → (=> (a: number b: number): number) — function type value
fn({a: g.number, b: g.number}, g.number).withBody(call(sym(‘+’), sym(‘a’), sym(‘b’))) // → (=> (a: number b: number): number (+ a b)) — function literal AST
fn({xs: g.vector(g.sym(‘T’))}, g.sym(‘T’)) .withGenerics(‘T’) .withBody(…)
params accepts either the array form (with optional/variadic flags) or an object literal {name: type, ...} for the common all-required case.
Parameters
| Parameter | Type |
|---|---|
params | readonly FnParam[] | Readonly<Record<string, AST>> |
returnType | AST |
Returns
host()
host(
value):HostAST
Defined in: build.ts:54
Host-value AST. Wraps a host-side value (TypeValue, TypedHostFn, GlispClosure, IO, opaque object) so the env can hand it back unchanged when evaluated. Distinct from lit because the source language has no way to express these values literally.
Parameters
| Parameter | Type |
|---|---|
value | unknown |
Returns
letBlock()
letBlock(
bindings,body?):LetAST
Defined in: build.ts:120
Let-block: bindings followed by an optional trailing expression.
letBlock([[‘a’, lit(10)], [‘b’, lit(20)]], call(sym(‘+’), sym(‘a’), sym(‘b’))) // → {a = 10 b = 20 (+ a b)}
Exported as g.let (the keyword form is allowed as a property name).
Parameters
| Parameter | Type | Default value |
|---|---|---|
bindings | readonly readonly [string, AST][] | undefined |
body | AST | null | null |
Returns
lit()
lit(
value):LitAST
Defined in: build.ts:44
Literal AST. Distinguishes between number / string / boolean / unit by JS type.
Parameters
| Parameter | Type |
|---|---|
value | string | number | boolean | typeof UNIT |
Returns
meta()
meta(
content,expr):MetaAST
Defined in: build.ts:208
Metadata-attached expression: ^{...meta} expr.
Accepts the same MetaContent form as the fluent .meta() method — an object whose values are AST nodes or plain JS primitives (auto-lifted to literals). The fluent form expr.meta({...}) is usually nicer; this function exists for cases where the wrapping order is more natural.
Parameters
| Parameter | Type |
|---|---|
content | MetaContent |
expr | AST |
Returns
path()
path(…
segments):PathAST
Defined in: build.ts:167
Path AST. Pass segments in order, where '..' means parent.
path(‘foo’) → ./foo path(‘…’, ‘foo’) → …/foo path(‘…’, ‘…’, ‘a’)→ …/…/a path() → ./ (the current node itself)
Parameters
| Parameter | Type |
|---|---|
…segments | readonly (string | number)[] |
Returns
quote()
quote(
expr):QuoteAST
Defined in: build.ts:174
Quasiquote: `expr.
Parameters
| Parameter | Type |
|---|---|
expr | AST |
Returns
record()
record(
fields):RecordAST
Defined in: build.ts:101
Record literal: {k1: v1 k2: v2 ...rec ...}.
Two input forms:
- Object literal
{x: lit(1), y: lit(2)}— keys collapse per JS rules (no duplicates / no spreads expressible). - Array of entries
[['x', lit(1)], spread(sym('rec')), ['y', lit(2)]]— preserves duplicates and letsSpreadASTentries appear inline. Evaluation applies last-wins (after expanding spreads) and emits a diagnostic for duplicates.
Parameters
| Parameter | Type |
|---|---|
fields | readonly RecordEntry[] | Readonly<Record<string, AST>> |
Returns
splice()
splice(
expr):SpliceAST
Defined in: build.ts:196
Unquote-splice: ...~expr. Only meaningful inside a quasiquote. For non-evaluating spread, use spread() instead.
Parameters
| Parameter | Type |
|---|---|
expr | AST |
Returns
spread()
spread(
expr):SpreadAST
Defined in: build.ts:188
Spread: ...expr. Inlines the operand into the surrounding call / vec / record / quasiquote. Use this for variadic/spread positions; it remains ...expr even inside a quasiquote.
Parameters
| Parameter | Type |
|---|---|
expr | AST |
Returns
sym()
sym(
name):SymAST
Defined in: build.ts:59
Symbol (bare identifier) AST. Use this for identifiers; lit is for values.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
unquote()
unquote(
expr):UnquoteAST
Defined in: build.ts:179
Unquote: ~expr.
Parameters
| Parameter | Type |
|---|---|
expr | AST |
Returns
vec()
vec(…
elements):VecAST
Defined in: build.ts:85
Vector literal: [e0 e1 ...].
Parameters
| Parameter | Type |
|---|---|
…elements | readonly AST[] |
Returns
vectorType()
vectorType(
T):VecAST
Defined in: build.ts:239
[...T] — vector type with element type T. Renders as [...T] in source.
Parameters
| Parameter | Type |
|---|---|
T | AST |