Small Lisp interpreter written in Swift.
This project uses the Swift Package Manager.
To build.
$ swift build
You can then run by providing a script as input.
$ swift run slisp examples/script.lisp
This project also implements a SwiftPM library that can be used in projects.
import SwiftLisp
...
func execute() {
let input = readInput()
do {
let env = try loadBaseFiles
let ast = try Parser.parse()
for expr in ast {
let result = try expr.eval(env)
print(result)
}
} catch let error {
print(error)
}
}
Check the examples
directory for more examples.
- Function definition
(define fib
(lambda (x)
(cond ((eq x 0) 0)
((eq x 1) 1)
('t
(+ (fib (- x 1))
(fib (- x 2)))))))
- HTTP request
(define url "https://jsonplaceholder.typicode.com/todos/1")
(request url)
- Convert JSON to associative list
(define url "https://jsonplaceholder.typicode.com/todos/1")
(define json (request url))
(define dict (json-to-assoc-list json))
dict
> [["id" 1] ["completed" 0] ["userId" 1] ["title" "delectus aut autem"]]