Swiftpack.co - Package - objecthub/swift-lispkit

LispKit Swift LispKit

Platform: macOS Language: Swift 5.1 IDE: Xcode 11.3 Carthage: compatible License: Apache

Overview

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.

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.

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).

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
  • 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 three different targets:

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

Architecture

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

Overview

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: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 5300 (delta 1), reused 14 (delta 1), pack-reused 5286
Receiving objects: 100% (5300/5300), 1.76 MiB | 132.00 KiB/s, done.
Resolving deltas: 100% (3724/3724), 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-numberkit.git
Fetching https://github.com/objecthub/swift-commandlinekit.git
Fetching https://github.com/objecthub/swift-markdownkit.git
Completed resolution in 6.47s
Cloning https://github.com/objecthub/swift-numberkit.git
Resolving https://github.com/objecthub/swift-numberkit.git at 2.3.2
Cloning https://github.com/objecthub/swift-markdownkit.git
Resolving https://github.com/objecthub/swift-markdownkit.git at 0.2.0
Cloning https://github.com/objecthub/swift-commandlinekit.git
Resolving https://github.com/objecthub/swift-commandlinekit.git at 0.3.1
[124/124] Linking LispKitRepl

The debug binary can be run by invoking .build/debug/LispKitRepl -d LispKit assuming that directory ~/Documents/LispKit contains a copy of the resources directory needed to run the command-line tool.

A release binary can be built like this:

> cd swift-lispkit
> swift build -c release -Xswiftc "-D" -Xswiftc "SPM"
Fetching https://github.com/objecthub/swift-numberkit.git
Fetching https://github.com/objecthub/swift-commandlinekit.git
Fetching https://github.com/objecthub/swift-markdownkit.git
Completed resolution in 4.02s
Cloning https://github.com/objecthub/swift-numberkit.git
Resolving https://github.com/objecthub/swift-numberkit.git at 2.3.2
Cloning https://github.com/objecthub/swift-markdownkit.git
Resolving https://github.com/objecthub/swift-markdownkit.git at 0.2.0
Cloning https://github.com/objecthub/swift-commandlinekit.git
Resolving https://github.com/objecthub/swift-commandlinekit.git at 0.3.1
[6/6] Linking LispKitRepl

The release binary can be run by invoking .build/release/LispKitRepl -r Sources/LispKit/Resources in the directory swift-lispkit (in which the binary was build above).

Assuming that directory ~/Documents/LispKit contains a copy of the resources directory, it is also possible to run the release binary by invoking .build/release/LispKitRepl -d LispKit.

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.

Github

link
Stars: 210

Used By

Total: 0

Releases

Release 1.8.3 - 2019-11-23 01:48:52

  • Bugfixes in the read-eval-print loop

Release 1.8.2 - 2019-11-22 01:11:38

  • Extend pattern language supported by library (lispkit datatype)
  • Support append-map and filter-map in (lispkit list); support fxsqrt in (lispkit math); new functions in (lispkit string): string-empty?, string-pad-center; string-concatenate now supports an optional separator character
  • Fix bug in (lispkit set) which was leading to multi-set behavior
  • New example code for solving Sudoku puzzles
  • Garbage collector optimizations
  • Refactored object types to make them more extensible
  • A new REPL framework is available via a new framework LispKitTools
  • New library: (srfi 175)

Release 1.8.1 - 2019-10-20 21:02:02

  • Update dependency on NumberKit 2.3.2
  • Update documentation
  • New libraries: (srfi 174), (srfi 177)

Release 1.8.0 - 2019-10-15 10:40:17

  • Migrated project to Xcode 11.1
  • Ported code to Swift 5.1
  • Simplify printed representation of procedures.
  • Rewrite of garbage collector: replaced recursive garbage collector with iterative version
  • Completed hash functions of library (lispkit hashtable)
  • New library: (lispkit comparator)
  • Several fixes in (lispkit math): integer->fx renamed to integer->fixnum, introduced fxlogical-shift-right and real->flonum, fixed bit-count, fixed fxmodulo to work with negative numbers
  • Statically link libraries. Removed Carthage support.

Release 1.7.2 - 2019-09-08 14:02:31

  • New libraries: (lispkit stream), (scheme mapping), (srfi 146), (srfi 165), (srfi 173)
  • Fixed memory leak involving recursive local functions
  • Support uninterned symbols
  • Implement algebraic datatypes in terms of more efficient internal functions
  • Extension and re-implementation of library (lispkit type)
  • Include miniAdapton in the new third-party directory
  • Support custom keywords in let-keywords
  • New example code for generating mazes
  • Migrated project to Xcode 10.3
  • Ported code to Swift 5

Release 1.7.0 - 2019-02-24 18:43:27

  • 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

Release 1.6.0 - 2019-01-04 00:04:32

  • 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

Maintenance Release 1.5.4 - 2018-11-03 10:34:46

  • 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

Maintenance Release 1.5.3 - 2018-10-21 00:04:39

  • 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

Maintenance Release 1.5.2 - 2018-09-16 20:34:35

  • 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

Maintenance Release 1.5.1 - 2018-08-19 07:47:22

  • Bugfixes and name changes in (lispkit draw)
  • New example code showcasing (lispkit draw) features

Release 1.5.0 - 2018-08-09 22:11:52

  • Allow importing multiple libraries with one import invocation
  • Mark continuations correctly and fix continuation?
  • Turn current-input-port, current-output-port, and current-error-port into parameter objects
  • New library: (lispkit draw)
  • New SRFI libraries: SRFI 111, SRFI 112, SRFI 113
  • Fixed bugs in SRFI 69
  • Extend (lispkit test) to be more compatible to similar libraries

Release 1.4.1 - 2018-06-22 23:07:24

  • Fix memory leaks
  • Provide a comfortable command-line interface supporting both a read-eval-print loop and the execution of scripts
  • Prelude and libraries path preferences are now handled correctly and do not result in access issues anymore
  • Programs blocking on functions like read can now be terminated
  • Minor bugs in bitwise operations for exact integers of arbitrary size fixed
  • string-split now returns a list instead of a vector
  • Complete rewrite of the error reporting subsystem, including support for file-error? and read-error?
  • New library: (lispkit test)
  • New SRFI libraries: SRFI 69, SRFI 129, SRFI 137, SRFI 145, SRFI 151
  • New example code for coroutines, HTTP support, and a small compiler for arithmetic expressions

Release 1.4.0 - 2018-03-30 18:15:20

  • Migrated project to Xcode 9.3 and Swift 4
  • Bug fixes (esp. in syntax-rules)
  • Fixed logic for referencing unquote, etc. in backquote.
  • Include native date/time operations and functionality for accessing user data
  • Native support for a few common string functions
  • Support for read-token (generalization of read-line)
  • Added libraries (lispkit stack), (lispkit queue), (lispkit logic)
  • Implement bitwise operations for exact integers of arbitrary size
  • Complete rewrite of the error reporting and representation sub-system
  • Preparations for managing source locations

Maintenance release 1.3.1 - 2017-12-17 00:13:01

  • Include native date/time operations and functionality for accessing user data
  • Native support for a few common string functions
  • Support for read-token (generalization of read-line)
  • Added libraries (lispkit stack) and (lispkit queue)
  • Bug fixes

Release 1.3 - 2017-12-03 14:51:57

  • Support simple HTTP API
  • Support compression for bytevectors
  • Implement call tracing
  • Fixed bug preventing some internal definitions to not work
  • Support all standard R7RS small Scheme libraries
  • Support for: (srfi 158), (lispkit wt-tree), (lispkit object)

First official release. - 2017-05-07 12:35:38