Skip to content

Latest commit

 

History

History
78 lines (63 loc) · 1.45 KB

README.md

File metadata and controls

78 lines (63 loc) · 1.45 KB

Mini Go Lisp

Go Report Card Actions Status

Mini lisp interpreter written in Go. It is implemented with reference to the 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

> (+ 1 2)
3
> (cons 1 '(2 3))
(1 2 3)
> (defun 1+ (n) (+ n 1))
1+
> (1+ 10)
11
> (defun abs (n) (if (< n 0) (- 0 n) n))
ABS
> (abs -1)
1
> (defun gcd (m n) (if (= (mod m n) 0) n (gcd n (mod m n))))
GCD
> (gcd 12 18)
6
> (defun fact (n) (if (< n 1) 1 (* n (fact (- n 1)))))
FACT
> (fact 10)
3628800
> (defun fib (n) (if (<= n 1) n (+ (fib (- n 1)) (fib (- n 2)))))
FIB
> (fib 11)
89

See eval_test.go for other examples of how it works.