• Stars
    star
    377
  • Rank 113,535 (Top 3 %)
  • Language
    Scheme
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Interpreter framework for Lisp-based extension and scripting languages on macOS and iOS. LispKit is based on the R7RS standard for Scheme. Its compiler generates bytecode for a virtual machine. LispKit is fully implemented in Swift 5.

LispKitย ย  Swift LispKit

Platform: macOS | iOS Language: Swift 5.7 IDE: Xcode 14.2 Carthage: compatible License: Apache

Overview

LispKit is a framework for building Lisp-based extension and scripting languages for macOS and iOS 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.

The NumericalScheme demo showcases how to create a derived LispKit interpreter that inherits everything from LispKit (without code duplication) and defines a new native as well as Scheme-based library.

The iOS version of the LispKit framework supports all libraries except for (lispkit system os). Library (lispkit draw) works consistently across iOS and macOS but does not support color lists on iOS. In general, the differences between the macOS and iOS version of the framework are minor. Interestingly, the iPhone 12 Pro (2020) seems to consistently outperform the MacBook Pro 16" (2019) for simple LispKit benchmarks.

LispPad implements a simple, lightweight, integrated development environment for LispKit on macOS with a Cocoa-based UI. The LispPad Library Reference documents the core LispPad and LispKit libraries in PDF form. On iOS, application LispPad Go provides a simple Scheme IDE based on LispKit. The source code of LispPad Go is available on GitHub. A much simpler command-line tool for iOS is included in the LispKit framework itself (see below).

Features

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

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
  • Literals in syntax-rules are not matched based on their definition but their symbol identity
  • 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:

Project

The project defines four different targets:

  • LispKit: the core interpreter framework, including all support files, for macOS
  • LispKit iOS: the core interpreter framework, including all support files, for iOS
  • LispKitTools: a framework for tools supporting LispKit; e.g. a read-eval-print framework for macOS
  • LispKitRepl: a command-line tool implementing a read-eval-print loop for macOS

Architecture

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, and
  4. a simple read-eval-print loop for macOS and iOS.

Details can be found in the LispKit Wiki.

Command-line tool

Overview

This project 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: Enumerating objects: 7020, done.
remote: Counting objects: 100% (365/365), done.
remote: Compressing objects: 100% (349/349), done.
remote: Total 7020 (delta 174), reused 201 (delta 10), pack-reused 6655
Receiving objects: 100% (7020/7020), 11.29 MiB | 5.20 MiB/s, done.
Resolving deltas: 100% (4853/4853), done.

Next, switch to Xcode and build the LispKit 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 "-D" -Xswiftc "SPM"
Fetching https://github.com/objecthub/swift-markdownkit.git from cache
Fetching https://github.com/objecthub/swift-numberkit.git from cache
Fetching https://github.com/objecthub/swift-sqliteexpress.git from cache
Fetching https://github.com/objecthub/swift-commandlinekit.git from cache
Fetching https://github.com/weichsel/ZIPFoundation.git from cache
Cloning https://github.com/objecthub/swift-sqliteexpress.git
Resolving https://github.com/objecthub/swift-sqliteexpress.git at 1.0.3
Cloning https://github.com/weichsel/ZIPFoundation.git
Resolving https://github.com/weichsel/ZIPFoundation.git at 0.9.12
Cloning https://github.com/objecthub/swift-markdownkit.git
Resolving https://github.com/objecthub/swift-markdownkit.git at 1.0.5
Cloning https://github.com/objecthub/swift-numberkit.git
Resolving https://github.com/objecthub/swift-numberkit.git at 2.3.9
Cloning https://github.com/objecthub/swift-commandlinekit.git
Resolving https://github.com/objecthub/swift-commandlinekit.git at 0.3.3
[180/180] Linking LispKitRepl

The debug binary can now be run like this:

.build/debug/LispKitRepl -r Sources/LispKit/Resources -d LispKit

It is possible to execute a Scheme program at Sources/LispKit/Resources/Examples/Channels.scm like this:

.build/debug/LispKitRepl -r Sources/LispKit/Resources -d LispKit Sources/LispKit/Resources/Examples/Channels.scm

For experimentation with a new resources directory (e.g. containing new or modified Scheme libraries), the binary can also be run via .build/debug/LispKitRepl -d LispKit assuming that directory ~/Documents/LispKit contains a copy of the resources directory.

There is also a Makefile which provides convenience build rules. Building and running the REPL can be achieved, e.g. by invoking make run (for the debug REPL) or make repl (for the release REPL). If a Scheme program should be executed instead of the REPL being run, the program variable needs to be set, e.g. as in make run program=path/to/program.scm. Details for building binaries or executing tests can be looked up in the Makefile.

Building and running the iOS tool

LispKitRepl iOS

Within Xcode, switch the scheme to the target LispKitRepl iOS and build and run the project. By default, this will invoke the iOS simulator and run an application "LispKitRepl iOS". The application has a chat-inspired UI in which Scheme commands can be entered at the bottom and sent to the interpreter via the "arrow-up" button. The interpreter will then execute the command and print the result in the console area above. There is a single button with a trash can in the toolbar for resetting the interpreter. This button turns into a button for cancelling running programs (e.g. if there is an infinite loop or other deadlock).

There is also a more advanced open-source iOS application called LispPad Go which implements a complete IDE for LispKit. LispPad Go is available from the iOS app store.

Requirements

The following technologies are needed to build the components of the LispKit framework. For building the command-line tool, all that is needed is the Swift Package Manager. For compiling the framework and trying the command-line tool directly in Xcode, the Swift Package Manager is not needed.

More Repositories

1

swift-markdownkit

A framework for parsing and transforming text in Markdown format written in Swift 5 for macOS, iOS, and Linux. The syntax is based on the CommonMark specification. The framework defines an abstract syntax for Markdown, provides a parser for parsing strings into abstract syntax trees, and comes with generators for HTML and attributed strings.
Swift
148
star
2

swift-numberkit

Advanced numeric data types for Swift 5, including BigInt, Rational, and Complex numbers.
Swift
54
star
3

swift-commandlinekit

Framework supporting the development of command-line tools in Swift on macOS and Linux. The framework supports managing command-line arguments, provides lightweight functions to deal with escape sequences, and defines an API for reading strings from the terminal.
Swift
51
star
4

swift-lisppad-ios

LispPad is a Scheme development environment for macOS based on the LispKit framework. LispPad Go implements a similar, but much simpler, application for iPhones and iPads.
Swift
34
star
5

swift-clformat

Implementation of Common Lisp's `format` procedure from scratch in Swift 5 as a more powerful and complete replacement of `printf`.
Swift
8
star
6

swift-numericalscheme

This Xcode project showcases how to extend Swift LispKit. The project implements a read-eval-print loop for an extended LispKit language supporting native flonum vectors and arrays.
Swift
7
star
7

swift-dynamicjson

Framework for representing, validating, querying, and manipulating generic JSON values in Swift. Supported are standards such as JSON Pointer (RFC 6901), JSON Path (RFC 9535), JSON Patch (RFC 6902), JSON Merge Patch (RFC 7396), and JSON Schema.
Swift
7
star
8

jaco

Extensible Java compiler framework.
Java
6
star
9

swift-sqliteexpress

SQLiteExpress is a small Swift 5 library implementing a wrapper for the C API of SQLite3 on macOS and iOS.
Swift
5
star
10

containerkit

Comprehensive container class library for the Go programming language.
Go
4
star
11

swift-nanohttp

A tiny extensible and configurable HTTP server framework written in Swift for macOS, iOS, and Linux.
Swift
3
star
12

SimpleSplitView

Swift
1
star
13

swift-lisppad-support

Framework providing implementations of LispPad-specific libraries and a macOS REPL that supports LispPad libraries.
Swift
1
star