https://github.com/d-tsuji/gosdlisp
Mini lisp interpreter written in Go.
https://github.com/d-tsuji/gosdlisp
go golang interpreter lisp lisp-interpreter mini-lisp
Last synced: 5 months ago
JSON representation
Mini lisp interpreter written in Go.
- Host: GitHub
- URL: https://github.com/d-tsuji/gosdlisp
- Owner: d-tsuji
- License: mit
- Created: 2020-05-18T14:00:40.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-27T12:18:05.000Z (almost 5 years ago)
- Last Synced: 2024-06-20T08:02:05.178Z (11 months ago)
- Topics: go, golang, interpreter, lisp, lisp-interpreter, mini-lisp
- Language: Go
- Homepage:
- Size: 91.8 KB
- Stars: 17
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Mini Go Lisp
============[](https://goreportcard.com/report/github.com/d-tsuji/gosdlisp)
[](https://github.com/d-tsuji/gosdlisp/actions)Mini lisp interpreter written in Go. It is implemented with reference to the [d-tsuji/SDLisp](https://github.com/d-tsuji/SDLisp) repository written in Java.
## Support
- System Functions
- `car`
- `cdr`
- `cons`
- `eq`
- `if`
- arithmetic operations (`+`, `-`, `*`, `/`)
- comparative operation (`>`, `<`, `>=`, `<=`, `=`)
- Special
- `symbol-function`
- `quote` or `'`
- `setq`
- `defun`## Usage
```
$ go run github.com/d-tsuji/gosdlisp/cmd/gosdlisp
```## Some examples
```lisp
> (+ 1 2)
3
``````lisp
> (cons 1 '(2 3))
(1 2 3)
``````lisp
> (defun 1+ (n) (+ n 1))
1+
> (1+ 10)
11
``````lisp
> (defun abs (n) (if (< n 0) (- 0 n) n))
ABS
> (abs -1)
1
``````lisp
> (defun gcd (m n) (if (= (mod m n) 0) n (gcd n (mod m n))))
GCD
> (gcd 12 18)
6
``````lisp
> (defun fact (n) (if (< n 1) 1 (* n (fact (- n 1)))))
FACT
> (fact 10)
3628800
``````lisp
> (defun fib (n) (if (<= n 1) n (+ (fib (- n 1)) (fib (- n 2)))))
FIB
> (fib 11)
89
```See [eval_test.go](https://github.com/d-tsuji/gosdlisp/blob/master/eval_test.go) for other examples of how it works.