GlispGlisp
Home
Guide
Playground
  • Overview
  • Syntax
  • Types
  • Evaluation
  • Host API
API
  • English
  • 日本語
GitHub
Home
Guide
Playground
  • Overview
  • Syntax
  • Types
  • Evaluation
  • Host API
API
  • English
  • 日本語
GitHub
  • API

    • glisp
    • build
    • check
    • eval
    • expand
    • expectedType
    • infer
    • lex
    • parse
    • print
    • session
    • types

glisp


glisp / build

build

Variables

astType

const astType: SymAST

Defined in: build.ts:234

The ast type — type of quoted forms / macro inputs and outputs.


booleanType

const booleanType: SymAST

Defined in: build.ts:226

The boolean type.


bottomType

const bottomType: SymAST

Defined in: build.ts:232

The ! (bottom) type.


g

const g: 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

NameTypeDefault value
access()(target, key) => AccessAST-
astSymASTastType
booleanSymASTbooleanType
bottomSymASTbottomType
call()(head, …args) => CallAST-
callKw()(head, args, kwargs) => CallAST-
enum()(…values) => CallASTenumType
fn()(params, returnType) => FnAST-
host()(value) => HostAST-
let()(bindings, body) => LetASTletBlock
lit()(value) => LitAST-
meta()(content, expr) => MetaAST-
numberSymASTnumberType
path()(…segments) => PathAST-
print()(ast) => string-
quote()(expr) => QuoteAST-
record()(fields) => RecordAST-
splice()(expr) => SpliceAST-
spread()(expr) => SpreadAST-
stringSymASTstringType
sym()(name) => SymAST-
topSymASTtopType
unitSymASTunitType
unquote()(expr) => UnquoteAST-
vec()(…elements) => VecAST-
vector()(T) => VecASTvectorType

numberType

const numberType: SymAST

Defined in: build.ts:222

The number type.


stringType

const stringType: SymAST

Defined in: build.ts:224

The string type.


topType

const topType: SymAST

Defined in: build.ts:230

The _ (top) type.


unitType

const unitType: 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

ParameterType
targetAST
keystring | number

Returns

AccessAST


call()

call(head, …args): CallAST

Defined in: build.ts:64

Application: (head a b ...).

Parameters

ParameterType
headAST
…argsreadonly AST[]

Returns

CallAST


callKw()

callKw(head, args, kwargs): CallAST

Defined in: build.ts:71

Application with keyword arguments: (head a b k1=v1 k2=v2).

Parameters

ParameterType
headAST
argsreadonly AST[]
kwargsReadonly<Record<string, AST>>

Returns

CallAST


enumType()

enumType(…values): CallAST

Defined in: build.ts:250

Parameters

ParameterType
…valuesreadonly (string | number | boolean)[]

Returns

CallAST


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

ParameterType
paramsreadonly FnParam[] | Readonly<Record<string, AST>>
returnTypeAST

Returns

FnAST


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

ParameterType
valueunknown

Returns

HostAST


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

ParameterTypeDefault value
bindingsreadonly readonly [string, AST][]undefined
bodyAST | nullnull

Returns

LetAST


lit()

lit(value): LitAST

Defined in: build.ts:44

Literal AST. Distinguishes between number / string / boolean / unit by JS type.

Parameters

ParameterType
valuestring | number | boolean | typeof UNIT

Returns

LitAST


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

ParameterType
contentMetaContent
exprAST

Returns

MetaAST


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

ParameterType
…segmentsreadonly (string | number)[]

Returns

PathAST


quote()

quote(expr): QuoteAST

Defined in: build.ts:174

Quasiquote: `expr.

Parameters

ParameterType
exprAST

Returns

QuoteAST


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 lets SpreadAST entries appear inline. Evaluation applies last-wins (after expanding spreads) and emits a diagnostic for duplicates.

Parameters

ParameterType
fieldsreadonly RecordEntry[] | Readonly<Record<string, AST>>

Returns

RecordAST


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

ParameterType
exprAST

Returns

SpliceAST


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

ParameterType
exprAST

Returns

SpreadAST


sym()

sym(name): SymAST

Defined in: build.ts:59

Symbol (bare identifier) AST. Use this for identifiers; lit is for values.

Parameters

ParameterType
namestring

Returns

SymAST


unquote()

unquote(expr): UnquoteAST

Defined in: build.ts:179

Unquote: ~expr.

Parameters

ParameterType
exprAST

Returns

UnquoteAST


vec()

vec(…elements): VecAST

Defined in: build.ts:85

Vector literal: [e0 e1 ...].

Parameters

ParameterType
…elementsreadonly AST[]

Returns

VecAST


vectorType()

vectorType(T): VecAST

Defined in: build.ts:239

[...T] — vector type with element type T. Renders as [...T] in source.

Parameters

ParameterType
TAST

Returns

VecAST

Edit this page
Prev
glisp
Next
check