Joseph Adams 0f90c8bd25 Code generation working, just about. Now need to implement control structures and some other stuff. | 10 年之前 | |
---|---|---|
generator | 10 年之前 | |
lexer | 10 年之前 | |
parser | 10 年之前 | |
play | 10 年之前 | |
LICENSE | 11 年之前 | |
README.md | 11 年之前 | |
example.gsp | 10 年之前 | |
gisp.go | 10 年之前 |
Simple (non standard) implementation of Lisp/Scheme in Go.
macrox
)(x y & rest)
> go build && ./gisp
prelude loaded!
>>
>> (macrox (defn add (x y) (+ x y)))
[[macrox [defn add [x y] [+ x y]]]]
[define add [lambda [x y] [+ x y]]]
>> (defmacro apply (fn xs) `(,fn ,@,xs))
[[defmacro apply [fn xs] [quasiquote [[unquote fn] [unquote-splice [unquote xs]]]]]]
<nil>
>> (apply * '(1 2 3 4 5))
[[apply * [quote [1 2 3 4 5]]]]
120
>> (defn adder (x) (lambda (y) (+ x y)))
[[defn adder [x] [lambda [y] [+ x y]]]]
<nil>
>> (adder 5)
[[adder 5]]
#<closure>
>> ((adder 5) 10)
[[[adder 5] 10]]
15
>> (defn triplet-adder (x) (lambda (y) (lambda (z) (+ x y z))))
[[defn triplet-adder [x] [lambda [y] [lambda [z] [+ x y z]]]]]
<nil>
>> (triplet-adder 5)
[[triplet-adder 5]]
#<closure>
>> ((triplet-adder 5) 10)
[[[triplet-adder 5] 10]]
#<closure>
>> (((triplet-adder 5) 10) 20)
[[[[triplet-adder 5] 10] 20]]
35
>> (defn factorial (x) (if (== x 1) x (* x (factorial (dec x)))))
[[defn factorial [x] [if [== x 1] x [* x [factorial [dec x]]]]]]
<nil>
>> (factorial 5)
[[factorial 5]]
120
>>
MIT