Swiftpack.co - Package - objecthub/swift-lispkit

LispKit Swift LispKit

Platform: macOS Language: Swift 5 IDE: Xcode 10.2 Carthage: compatible License: Apache


LispKit is a framework for building Lisp-based extension and scripting languages for macOS applications. LispKit is fully written in the programming language Swift. LispKit implements a core language based on the R7RS (small) Scheme standard. It is extensible, allowing the inclusion of new native libraries written in Swift, of new libraries written in Scheme, as well as custom modifications of the core environment consisting of a compiler, a virtual machine as well as the core libraries.

So far, performance was not a priority in the development of LispKit. The LispKit compiler does not perform many code optimizations and the performance of the system is below state of the art Lisp and Scheme implementations.

LispPad implements a simple, lightweight, integrated development environment for LispKit on macOS with a Cocoa-based UI. A simpler command-line tool with similar functionality is provided by the LispKit framework itself (see below).


LispKit provides support for the following core features, many of which are based on R7RS:

  • Modules based on R7RS libraries
  • Hygienic macros based on syntax-rules
  • First-class environments
  • call/cc, dynamic-wind and exceptions
  • Dynamically-scoped parameters
  • Multiple return values
  • Delayed execution via promises and streams
  • Support for the full numerical tower consisting of arbitrary size integers, rationals, real numbers, and inexact complex numbers.
  • Unicode strings and characters
  • Vectors and bytevectors
  • Text and binary ports
  • R7RS-compliant records
  • R6RS-compliant hashtables
  • R6RS-compliant enumerations
  • All R7RS (small) libraries: (scheme base), (scheme case-lambda), (scheme char), (scheme complex), (scheme cxr), (scheme eval), (scheme file), (scheme inexact), (scheme lazy), (scheme load), (scheme process-context), (scheme read), (scheme repl), (scheme time), (scheme write), (scheme r5rs)
  • Some R7RS (large) libraries from Scheme Red and Scheme Tangerine editions: (scheme box), (scheme charset), (scheme comparator), (scheme generator), (scheme hash-table), (scheme ideque), (scheme list), (scheme mapping), (scheme rlist), (scheme set), (scheme sort), (scheme stream), (scheme text), (scheme vector)
  • LispKit-specific libraries: (lispkit box), (lispkit type), (lispkit hashtable), (lispkit log), (lispkit test), (lispkit match), (lispkit datatype), (lispkit object), (lispkit clos), (lispkit enum), (lispkit logic), (lispkit iteration), (lispkit gvector), (lispkit set), (lispkit stack), (lispkit queue), (lispkit heap), (lispkit graph), (lispkit wt-tree), (lispkit stream), (lispkit prettify), (lispkit json), (lispkit csv), (lispkit char-set), (lispkit date-time), (lispkit regexp), (lispkit draw), (lispkit draw turtle), and (lispkit pdf)

LispKit is incompatible or incomplete with respect to the following R7RS features:

  • Lists are immutable. Mutable cons-cells are supported in a way similar to Racket
  • Datum comments introduced via #; do not always work as in other Scheme dialects.

The following SRFI libraries have been ported to LispKit and are included in the framework:


From an architectural perspective, LispKit consists of:

  1. a compiler translating LispKit expressions into bytecode,
  2. a virtual machine for interpreting the generated bytecode. The virtual machine is stack-based, handles tail calls and continuations, and provides a garbage collector.
  3. a large range of libraries, all packaged together with the framework.

Details can be found in the LispKit Wiki.

Command-line tool


This project also includes a command-line tool, called the LispKit Shell, for executing LispKit applications in the terminal. It can be used to try out and experiment with the LispKit framework. The command-line tool can also be used interactively as a read-eval-print loop. The read-eval-print loop parses the entered LispKit expression, compiles it to bytecode, executes it, and displays the result.

Downloading the source code

First, clone the LispKit repository via git. The following command will create a directory swift-lispkit.

> git clone https://github.com/objecthub/swift-lispkit.git
Cloning into 'swift-lispkit'...
remote: Counting objects: 1849, done.
remote: Compressing objects: 100% (39/39), done.
remote: Total 1849 (delta 9), reused 0 (delta 0), pack-reused 1806
Receiving objects: 100% (1849/1849), 689.43 KiB | 666.00 KiB/s, done.
Resolving deltas: 100% (1430/1430), done.

Running the command-line tool in Xcode

Fetch dependencies and build them from scratch via carthage:

> cd swift-lispkit
> carthage bootstrap
*** Checking out swift-numberkit at "1.6.0"
*** xcodebuild output can be found in /var/folders/c_/h31lvvtx72s3zhc9bvxd0p480000gn/T/carthage-xcodebuild.46W8Z7.log
*** Building scheme "NumberKit (shared)" in NumberKit.xcodeproj

Now, it's possible to switch to Xcode and build the command-line tool via scheme LispKitRepl:

> open LispKit.xcodeproj

Compiling the command-line tool with the Swift Package Manager

A debug binary can be built in the following way:

> cd swift-lispkit
> swift build -Xswiftc "-target" -Xswiftc "x86_64-apple-macosx10.12" \
  -Xswiftc "-D" -Xswiftc "SPM"
Compile Swift Module 'NumberKit' (6 sources)
Compile Swift Module 'CommandLineKit' (15 sources)
Compile Swift Module 'LispKit' (83 sources)
Compile Swift Module 'LispKitRepl' (2 sources)
Linking ./.build/x86_64-apple-macosx10.10/debug/LispKitRepl

A release binary can be built like this:

> cd swift-lispkit
> swift build -c release -Xswiftc -static-stdlib -Xswiftc "-target" \
  -Xswiftc "x86_64-apple-macosx10.12" -Xswiftc "-D" -Xswiftc "SPM"
Compile Swift Module 'NumberKit' (6 sources)
Compile Swift Module 'CommandLineKit' (15 sources)
Compile Swift Module 'LispKit' (83 sources)
Compile Swift Module 'LispKitRepl' (2 sources)
Linking ./.build/x86_64-apple-macosx10.10/release/LispKitRepl


The following technologies are needed to build the components of the LispKit framework. For the command-line tool, Xcode and Carthage are not strictly needed. Just for compiling the framework and trying the command-line tool in Xcode, the Swift Package Manager is not needed.


Stars: 205
Help us keep the lights on

Used By

Total: 0


1.7.0 - Feb 24, 2019

  • New libraries: (lispkit csv), (lispkit match), (lispkit regexp), (lispkit gvector), (lispkit date-time)
  • Extended (lispkit vector) and (lispkit list) libraries
  • Support for let-keywords and let*-keywords in library (lispkit control)
  • Complete re-write of library import and export logic fixing numerous bugs and incompatibilities with R7RS
  • Improved reporting of errors in library definitions
  • Support call tracing for individual procedures
  • Make the last three REPL results available via *1, *2, and *3
  • Allow @ as initial character in identifiers

1.6.0 - Jan 4, 2019

  • New libraries: (lispkit log), (lispkit char-set), (scheme char), (srfi 14 ascii), (srfi 101), (srfi 125)
  • Support Scheme libraries from R7RS large/Red edition: (scheme box), (scheme charset), (scheme comparator), (scheme generator), (scheme hash-table), (scheme ideque), (scheme list), (scheme rlist), (scheme set), (scheme sort), (scheme stream), (scheme text), (scheme vector)
  • Extended library (lispkit test): support nested test groups, approximate tests, and handle exceptions correctly
  • Handle closing of ports correctly in library (lispkit port)
  • Fix major bug in library (lispkit system) affecting the composition of file paths
  • Bug fixes affecting bytevector-copy!, fold-left, max, min, numerator, denominator, log, magnitude, gcd and lcm, as well as the escaping of symbols
  • Move from #\dx???? syntax to #\x???? to represent character literals
  • Return more user-friendly error messages for operating system errors

1.5.4 - Nov 3, 2018

  • Migrated project to Xcode 10.1 and ported code to Swift 4.2.1
  • Included implementation of "Tiny CLOS" as library (lispkit clos)
  • New SRFI libraries: SRFI 23, SRFI 34, SRFI 39, SRFI 95

1.5.3 - Oct 21, 2018

  • Migrated project to Xcode 10.0 and ported code to Swift 4.2
  • Small bug fixes in library (lispkit draw)
  • Fixed serious hashing bug (crashing LispKit)
  • New SRFI library: SRFI 14, SRFI 16

1.5.2 - Sep 16, 2018

  • Several substantial extensions of library (lispkit draw)
  • Support for turtle graphics via library (lispkit draw turtle)
  • New example code showcasing (lispkit draw turtle) features
  • New SRFI library: SRFI 161