Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Libraries

Every library that ships lives under src/, at the path its name gives: (snail shell graphics scan) is src/snail/shell/graphics/scan.sld. They come in layers, each importing only from the layers before it:

  • Core, (snail core …), imports nothing outside itself. The compiler imports only its base, table and io, so it can compile itself.
  • Runtime interfaces, (snail runtime …), declare one host interface’s WebAssembly imports and nothing else, so they emit no code of their own.
  • The shell, (snail shell …), is everything else: written in snail-scheme over core and the runtime interfaces. The compiler, the build and the language server are shell libraries too.
  • Targets, (snail target …), run a program’s main and give it the capabilities it asks for.
  • Application support: (lpc …) draws Liberated Pixel Cup characters, (datasets …) links published datasets into programs, and each application under src/apps/ keeps libraries of its own.

There are no (scheme …) compatibility libraries and no dynamic numeric tower.

Reading a library

A library’s header comment, at the top of its file, says what it is for and how it is used, usually with an example. Sections, each headed ;; ---- Title ----, divide the rest, and a compiler module’s unit tests sit in a final Tests section. This reference says what each library is for, names its main entry points, and records what its code does not say: why it is shaped as it is, what it costs, and how it fits with the others. For anything finer, read the source, which each section links.

Three conventions run through the shell:

  • A capability is a record of functions a function is handed, such as an OutputPort, a Gpu or a Dom. host-NAME makes the host’s from a Host, which only a target holds, and main asks its target for what it needs by its parameters’ types (capabilities).
  • A page variant and a test variant. (… page) libraries make a capability over the browser page, and (snail shell dom memory) and (snail shell gpu record) make ones that need no page or device, so an interface or a graphics library is tested in an ordinary program.
  • Waiting is suspension. An operation that waits for the host, such as reading a file or a buffer, suspends the task that called it and nothing else (task operations).

Index

Core

LibraryFor
(snail core forms)The core forms and builtin types, served by the compiler
(snail core primitive)The operations the backend implements, with their types
(snail core base)The prelude: forms, numbers, Option, Result, lists, arrays, strings, prompts
(snail core io)Ports, files and directories, the clock, arguments and environment
(snail core table)Immutable tables from strings to values

Text and data

LibraryFor
(snail shell math)Elementary functions on F64, bit for bit libm’s
(snail shell random)A deterministic generator as a value
(snail shell text)Unicode properties and case mapping
(snail shell utf8)Strict UTF-8 encoding and decoding
(snail shell json), (snail shell json read)JSON values, written as JSON.stringify writes them, and read back
(snail shell wire)Values to bytes and back, checked against their schema
(snail shell syntax)The syntax a generate-library recipe returns
(snail shell inflate)DEFLATE streams, decompressed
(snail shell zip)Zip archives, read a member at a time from the bytes given
(snail shell compiler sha256)SHA-256, the same on both hosts

Tasks, files, processes and networks

LibraryFor
(snail shell task)Cooperative tasks, their scheduler, waits and mailboxes
(snail shell async-files)Whole-file reads that wait as a task
(snail shell resource)Files a library links instead of embedding
(snail shell process)Child processes, commands run to their end, and signals
(snail shell socket)TCP and UDP
(snail shell http), (snail shell http exchange)A bounded subset of HTTP/1.1, and one exchange over a connection
(snail shell web)The length of the file at a URL, and parts of it, on Node
(snail shell web zip)Zip archives on the web, pinned, their members kept in the machine’s cache
(snail shell wasm)Compiling, linking and calling WebAssembly modules
(snail shell explore)Bounded model checking of a state machine

Pages, documents and interfaces

LibraryFor
(snail shell page)What every page program shares: its events, its save and its boot
(snail shell app)Canvas applications: a scene drawn each frame, and a HUD
(snail shell ui), (snail shell ui page)Document interfaces in the shape Elm gave them
(snail shell dom), (snail shell dom page), (snail shell dom memory)A document as a capability, over the page or in memory
(snail shell fetch), (snail shell fetch page)Requests and server-sent events
(snail shell files), (snail shell files page)Files the user drops on the page or picks
(snail shell base64)Encode bytes as a data URL
(snail shell png)PNG files and data URLs of RGBA pixels
(snail shell sprite)Animations on sheets of equal cells

The GPU

LibraryFor
(snail shell gpu), (snail shell gpu record)WebGPU as a capability, and one that records instead of running
(snail shell graphics pod)Records laid out as WGSL lays out its structs
(snail shell graphics wgsl)Shaders as S-expressions, printed to WGSL at build time
(snail shell graphics kernel)What every library of compute kernels needs
(snail shell graphics scan)An exclusive prefix sum on the GPU
(snail shell graphics radix-sort)A stable radix sort of keys and values on the GPU

Rasterized graphics

LibraryFor
(snail shell graphics atlas)Pictures composed into texture-array pages
(snail shell graphics quad)2D quads from those pages, one instanced draw a run
(snail shell graphics mesh)Meshes as geometry and instance tables
(snail shell graphics raster)A G-buffer, and translucent surfaces over it
(snail shell graphics passes)The sun, tone mapping and FXAA
(snail shell graphics fly)A camera that flies

Gaussian splats

LibraryFor
(snail shell graphics splat)Gaussians drawn as sorted, blended quads
(snail shell graphics ply)3D Gaussian Splatting’s PLY files, read and written
(snail shell graphics colmap)COLMAP’s sparse reconstructions
(snail shell graphics splat-view)Gaussians drawn tile by tile, as training draws them
(snail shell graphics splat-train)The differentiable splat renderer, as a tensor graph
(snail shell graphics splat-fit)Training: a step, densification and the opacity reset

Path tracing

LibraryFor
(snail shell graphics bvh)A BVH over triangles, and ray queries through it
(snail shell graphics environment)Light from all around: an HDR file or a sky
(snail shell graphics gltf)glTF 2.0 scenes, read
(snail shell graphics animation), (snail shell graphics gltf animation)Generic rigs, authored clips and glTF skins
(snail shell graphics trace scene)A glTF scene on the device
(snail shell graphics svgf)A denoiser for one path a pixel
(snail shell graphics trace render)A scene path traced to the canvas

Game simulation and stories

LibraryFor
(snail shell game physics), terrain, vehicle, boardingCPU movement, vehicle kinematics and riders
(snail shell game humanoid), pedestrianCharacter poses and walking behavior
(snail shell game drawing), figure, sceneryRigid parts and their placement
(snail shell game quest)Typed stage and event rules
(snail shell game dialogue)Spoken lines, branching replies and saved cursors
(snail shell game ink)Generate a dialogue library from linked Ink sources

Tensors

LibraryFor
(snail shell tensor)Tensor graphs of nodes and views
(snail shell tensor grad)Reverse-mode gradients, as more graph
(snail shell tensor adam)Adam’s update, as more graph
(snail shell tensor fuse)Fusing maps into fewer kernels
(snail shell tensor lower)A graph lowered to WebGPU buffers and dispatches
(snail shell tensor eval)A graph evaluated on the CPU, the kernels’ specification

Tools

LibraryFor
(snail shell compiler) and its passesSource to WebAssembly text, written in snail-scheme
(snail shell assembler)WebAssembly text to a module, and static linking, in-process
(snail shell project build), (snail shell project web-app)Builds of scripts, and a page’s web-app manifest
(snail shell lsp)The language server
(snail shell format)The formatter
(snail shell highlight)Source text as classified tokens, for coloring

Runtime interfaces and targets

LibraryFor
(snail runtime browser …)The page’s events, save, document, requests and files
(snail runtime gpu)The host’s WebGPU device
(snail runtime native …)Node’s sockets, processes, asynchronous files and the web
(snail runtime resource), (snail runtime wasm)Linked files and WebAssembly on every host
(snail target node), (snail target browser)The two targets

Liberated Pixel Cup art

LibraryFor
(lpc layout)The geometry of LPC character sheets
(lpc catalog)Which LPC bodies, heads, hair and garments the packs draw, and where
(lpc wardrobe)Characters dressed from the catalog, as pictures
(lpc skins)The skin ramps, read when built
(lpc credits), (lpc embed)Credits for what a program embeds, and recipes that embed it

Datasets

LibraryFor
(datasets mipnerf360)Mip-NeRF 360’s scenes, read from Google’s archives when built
(datasets mipnerf360 bicycle), and the other eight scenesOne scene’s reconstruction and photographs, at the size 3D Gaussian Splatting trains it

Applications’ own libraries

Each application keeps its libraries beside its scripts, under src/apps/NAME/:

  • (apps siegework …): the colony game’s land, rules, siege, view and HUD (Siegework).
  • (apps hearsay …): the rumor mill and the favor ledger, their screens and their LPC cast (Hearsay’s README).
  • (apps train …): 3D Gaussian Splatting training, on a page or on Node (training on photographs).
  • (apps splats rings): the cloud the splat viewer opens on (gaussian splats).