koans.app

Scheme Koans

Scheme is a Lisp reduced to its essentials: a few forms, lists to hold both data and code, and functions as values. Its small size has made it the language of classic computer science books and courses, and a laboratory for ideas such as tail calls, continuations and hygienic macros. These koans follow R7RS, its current standard: lists and pairs, recursion, higher-order functions, closures, records, continuations and macros.

74 koans in 19 groups, tested with SRFI 64. Each is a small program whose tests fail: replace every ___ until they pass.

Start the path

Awakening

How a koan checks your answers, and what Scheme counts as true.

  1. Tests
  2. Expressions
  3. Truth
  4. Quote
  5. Equivalence

Numbers

Arithmetic on whole numbers, and the functions that work on them.

  1. Arithmetic
  2. Integer division
  3. Questions about numbers
  4. Number functions

Pairs and lists

The pair, Scheme's building block, and the lists made from pairs.

  1. Pairs
  2. Lists are pairs
  3. Building lists
  4. Reaching into lists
  5. Searching lists

Strings and characters

Text, the characters it's made of, and symbols.

  1. Strings
  2. Characters
  3. Strings and lists
  4. Symbols

Vectors

Fixed-size collections, indexed in constant time.

  1. Vectors
  2. Changing vectors
  3. Vector procedures

Definitions

Naming values and procedures, and the forms that bind names.

  1. Define and lambda
  2. Parameters
  3. Let
  4. Internal definitions
  5. Multiple values

Control flow

Choosing what to do: if, cond, case, and loops.

  1. If and cond
  2. Case
  3. When, unless, and, or
  4. Do loops

Recursion

Procedures that call themselves, and loops that are really recursion.

  1. Recursion
  2. Recursion on lists
  3. Tail calls
  4. Named let
  5. Mutual recursion

Trees

Lists inside lists: recursion in two directions.

  1. Nested lists
  2. Flatten
  3. Mapping a tree

Higher-order procedures

Procedures that take or return procedures.

  1. Map and for-each
  2. Filter and fold
  3. Searching with procedures
  4. Apply
  5. Procedures that return procedures

Closures and state

Procedures that keep their surroundings, and values that change.

  1. Closures
  2. Message passing
  3. Memoization
  4. Parameter objects

Association lists

Lists of pairs used as small tables.

  1. Association lists
  2. Updating association lists
  3. Counting with association lists

Records

Defining your own types with define-record-type.

  1. Records
  2. Changing records
  3. Working with records

Laziness

Delaying a computation until its value is needed.

  1. Delay and force
  2. Streams
  3. Ready-made promises

Continuations

call/cc: the rest of the computation, as a procedure.

  1. Escaping
  2. Early exit
  3. Dynamic-wind

Errors

Raising errors and handling them.

  1. Error and guard
  2. Error objects
  3. Raising anything
  4. Exception handlers

Macros

Code is data: quasiquote, and macros that rewrite code.

  1. Quasiquote
  2. Syntax-rules
  3. Ellipses and recursive macros
  4. Hygiene

Ports

Reading and writing text through string ports.

  1. Output ports
  2. Input ports

Puzzles

Small programs to read and predict.

  1. FizzBuzz
  2. Quicksort
  3. Run-length encoding
  4. Roman numerals
  5. Sets as lists