Other

kite

Scheme interpreter in Swift

A Scheme interpreter written in Swift, with an interactive REPL console and a runner for .scm files. It supports continuations, macros and exact arithmetic on arbitrarily large numbers.

kite

About the project

kite is a Scheme interpreter in Swift with call/cc continuations, tail recursion in constant space and hygienic syntax-rules macros. A continuation is the remembered rest of a computation that a program can return to, and hygienic macros do not mix their names with the names in the user's code. The interpreter computes with integers of any size and exact fractions, so results lose no precision. Programs are typed in live in the REPL, an interactive console.

The challenge

Scheme demands two things you cannot build on the stack of the language the interpreter is written in: first-class continuations you can return to after they have already produced a result, and tail recursion with no depth limit. A naive recursive evaluator in Swift delivers neither.

What we did

  1. 01

    A Scheme interpreter in Swift: an S-expression reader, a REPL and a .scm file runner

  2. 02

    A CEK machine in which the continuation is plain data

  3. 03

    Re-entrant call/cc and tail recursion in constant space

  4. 04

    Hygienic syntax-rules macros with literals and ellipses

  5. 05

    A numeric tower: a hand-written BigInt, exact fractions and floating point

  6. 06

    XCTest suites for every layer and for the example programs

Related projects

Describe your project.

A free quote comes back within an hour during working hours.

Tell us what you want to build.

A free quote comes back within an hour during working hours. You talk to the person who writes the code.