objecthub / 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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swift NumericalScheme

Platform: macOS Language: Swift 5.7 IDE: Xcode 14 Carthage: compatible License: Apache 2.0

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. The flonum vectors are implemented in terms of a new native LispKit library (numerical vector), the flonum array library is implemented as a regular Scheme library (numerical array) and uses the flonum vector library in its implementation.

Building the tool

Xcode

git clone https://github.com/objecthub/swift-numericalscheme
cd swift-numericalscheme
carthage bootstrap --platform macOS
open NumericalScheme.xcodeproj

The NumericalScheme command-line tool is built via the scheme NumericalScheme of the Xcode project and can be executed directly in Xcode. For running the tool in a terminal, using the Swift Package Manager is the preferred approach.

Swift Package Manager

git clone https://github.com/objecthub/swift-numericalscheme
cd swift-numericalscheme
swift build -c release -Xswiftc "-D" -Xswiftc "SPM"

This will statically link all libraries into one binary .build/release/NumericalScheme. For executing the binary, the tool needs access to the supplemental files coming with LispKit as well as with NumericalScheme itself. These are typically provided via the -r (i.e. --roots) command-line argument. The order of the directory paths matter; i.e. the second path is searched before the first path, so by specifying the NumericalScheme path first, it will be possible to override definitions/libraries provided by the LispKit framework.

This is how the NumericalScheme command-line tool can be invoked (assuming the current directory is the root directoy swift-numericalscheme):

.build/release/NumericalScheme -r .build/checkouts/swift-lispkit/Sources/LispKit/Resources Sources/NumericalScheme/Resources

Testing the tool

After starting up the tool, enter the following command in the read-eval-print loop:

(load "Examples/Matrix")

This will load and execute the test program Matrix.scm. If executing the command will results in the output below, everything is set up correctly:

#f64array:(#<f64vector: 1.0 6.0 11.0 2.0 7.0 12.0 3.0 8.0 13.0 4.0 9.0 14.0 5.0 10.0 15.0> 3 5)

Requirements

The following technologies and components are needed to build the NumericalScheme command-line tool:

About

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.

License:Apache License 2.0


Languages

Language:Swift 80.8%Language:Scheme 19.2%