LispKit
LispKit comes with a collection of example programs in its Examples folder. The pages in this section present some of them as illustrated examples. Each page describes what the program does, shows how to run it, explains the ideas behind it, and walks through the complete source code, piece by piece. The results shown on the pages come from running the programs. At the end, every page suggests variations to try and points to the documentation of the libraries involved.
Overview
| Example | What it shows | Main libraries |
|---|---|---|
| AVL Trees | A library of purely functional, self-balancing search trees, defined inside the program itself. An algebraic datatype, pattern matching, and four kinds of rotations keep the trees balanced. | (lispkit datatype), (lispkit base) |
| Channels | Ten short programs for threads that communicate through channels: synchronous and buffered channels, select, timeouts, tickers, worker pools, and rate limiting. Adapted from Go by Example. | (lispkit thread), (lispkit thread channel) |
| Coroutines | Cooperative threads built from first-class continuations in about 30 lines of Scheme: spawn, yield, quit, and a round-robin scheduler. After an article by Matt Might. | (lispkit base), (srfi 31) |
| Image Composition | Finds the display of a billboard in a photo and projects another photo onto it, using perspective correction and image filters. | (lispkit vision), (lispkit image), (lispkit image process) |
| JSON | A guided tour through creating, querying, changing, merging, writing, and validating JSON values, including JSON Path, JSON Patch, CBOR, and JSON Schema. | (lispkit json), (lispkit json schema) |
| Markdown TOC | Inserts a table of contents into a Markdown document: pattern matching on the syntax tree extracts the headings, builds a nested list of links, and demotes the headings. The result is written as Markdown source and saved as PDF and RTFD documents. | (lispkit markdown), (lispkit datatype) |
| Maze | A small framework for mazes: two generation algorithms, a solver, and output on the terminal and in PDF files. Defines a library of its own. | (lispkit draw) |
| Movies | Collects movies from the web API of The Movie Database, merges the results of several overlapping queries into a local SQLite database, and reports statistics. Credentials come from environment variables or the system keychain. | (lispkit http), (lispkit sqlite), (lispkit system keychain) |
| OCR | Straightens the photo of a printed page, recognizes its text, and saves PDF files in which the recognized lines are marked up as drawings and as annotations. | (lispkit vision), (lispkit image), (lispkit pdf) |
| Polynomials | A small computer algebra program that turns polynomial expressions into canonical form. Ported from Peter Norvig's book on artificial intelligence programming. | (lispkit base) |
| Turtle | Three fractal curves, a fern, the C-curve, and the dragon curve, drawn with turtle graphics and saved as a multi-page PDF file. | (lispkit draw), (lispkit draw turtle) |
| Webserver | A multi-threaded web server with routing, middleware, forms, file sharing, and HTML written as Scheme data. | (lispkit http server) |
Find an example by topic
- Concurrency: Channels shows how threads cooperate by exchanging messages, and Coroutines builds a scheduler for cooperative threads from continuations. The Webserver runs its request handlers on threads.
- Graphics and PDF files: Turtle and Maze create vector drawings and save them as PDF files. OCR creates PDF files with annotations. Markdown TOC saves a Markdown document as a PDF file, with its diagram and formulas typeset.
- Images and computer vision: Image Composition and OCR detect rectangles and text with Apple's Vision framework and process images with Core Image. They run on macOS and iOS only.
- Data formats and databases: JSON covers JSON, JSON Path, JSON Patch, CBOR, and JSON Schema. Markdown TOC turns Markdown into a syntax tree, transforms it, and writes it back as Markdown. Movies keeps data in a SQLite database and merges data from several sources with transactions and upserts.
- Networking: The Webserver serves HTML pages, forms, and file downloads over HTTP. It requires LispKit 2.6.3 or later. Movies is the client side: it sends authenticated requests to a web API, several at a time, and keeps the credentials in the system keychain.
- Data structures and algorithms: AVL Trees implements a self-balancing search tree as an abstract data type. Maze generates and solves mazes.
- Symbolic computation: Polynomials represents and simplifies algebraic expressions.
- Language features: Coroutines uses continuations, AVL Trees and Maze define their own libraries, AVL Trees and Markdown TOC take apart and build trees with pattern matching, and Polynomials uses
define-type.