> For the complete documentation index, see [llms.txt](https://objecthub.gitbook.io/lisppad/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://objecthub.gitbook.io/lisppad/examples/lispkit.md).

# LispKit

A selection of illustrated LispKit example programs

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](/lisppad/examples/lispkit/avltrees.md)                 | 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](/lisppad/examples/lispkit/channels.md)                  | 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](/lisppad/examples/lispkit/coroutines.md)              | 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](/lisppad/examples/lispkit/imagecomposition.md) | 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](/lisppad/examples/lispkit/json.md)                          | 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](/lisppad/examples/lispkit/markdowntoc.md)           | 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](/lisppad/examples/lispkit/maze.md)                          | 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](/lisppad/examples/lispkit/movies.md)                      | 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](/lisppad/examples/lispkit/ocr.md)                            | 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](/lisppad/examples/lispkit/polynomials.md)            | 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](/lisppad/examples/lispkit/turtle.md)                      | 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](/lisppad/examples/lispkit/webserver.md)                | 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](/lisppad/examples/lispkit/channels.md) shows how threads cooperate by exchanging messages, and [Coroutines](/lisppad/examples/lispkit/coroutines.md) builds a scheduler for cooperative threads from continuations. The [Webserver](/lisppad/examples/lispkit/webserver.md) runs its request handlers on threads.
* **Graphics and PDF files:** [Turtle](/lisppad/examples/lispkit/turtle.md) and [Maze](/lisppad/examples/lispkit/maze.md) create vector drawings and save them as PDF files. [OCR](/lisppad/examples/lispkit/ocr.md) creates PDF files with annotations. [Markdown TOC](/lisppad/examples/lispkit/markdowntoc.md) saves a Markdown document as a PDF file, with its diagram and formulas typeset.
* **Images and computer vision:** [Image Composition](/lisppad/examples/lispkit/imagecomposition.md) and [OCR](/lisppad/examples/lispkit/ocr.md) 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](/lisppad/examples/lispkit/json.md) covers JSON, JSON Path, JSON Patch, CBOR, and JSON Schema. [Markdown TOC](/lisppad/examples/lispkit/markdowntoc.md) turns Markdown into a syntax tree, transforms it, and writes it back as Markdown. [Movies](/lisppad/examples/lispkit/movies.md) keeps data in a SQLite database and merges data from several sources with transactions and upserts.
* **Networking:** The [Webserver](/lisppad/examples/lispkit/webserver.md) serves HTML pages, forms, and file downloads over HTTP. It requires LispKit 2.6.3 or later. [Movies](/lisppad/examples/lispkit/movies.md) 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](/lisppad/examples/lispkit/avltrees.md) implements a self-balancing search tree as an abstract data type. [Maze](/lisppad/examples/lispkit/maze.md) generates and solves mazes.
* **Symbolic computation:** [Polynomials](/lisppad/examples/lispkit/polynomials.md) represents and simplifies algebraic expressions.
* **Language features:** [Coroutines](/lisppad/examples/lispkit/coroutines.md) uses continuations, [AVL Trees](/lisppad/examples/lispkit/avltrees.md) and [Maze](/lisppad/examples/lispkit/maze.md) define their own libraries, [AVL Trees](/lisppad/examples/lispkit/avltrees.md) and [Markdown TOC](/lisppad/examples/lispkit/markdowntoc.md) take apart and build trees with pattern matching, and [Polynomials](/lisppad/examples/lispkit/polynomials.md) uses `define-type`.
