g0dzill3r / lispy

Scheme interpreter in Kotlin
0 stars 0 forks source link

Add support for unquote splicing #25

Open g0dzill3r opened 1 year ago

g0dzill3r commented 1 year ago
> (quasiquote (0 1 2))
'(0 1 2)
> (quasiquote (0 (unquote (+ 1 2)) 4))
'(0 3 4)
> (quasiquote (0 (unquote-splicing (list 1 2)) 4))
'(0 1 2 4)
> (quasiquote (0 (unquote-splicing 1) 4))
unquote-splicing: contract violation
  expected: list?
  given: 1
> (quasiquote (0 (unquote-splicing 1)))
'(0 . 1)
g0dzill3r commented 1 year ago

Working except for the dotted pair situation.

repl> (define x 12345)
repl> `(a b ,(list 'c x) ,@(list x x x))
=> (a b (c 12345) 12345 12345 12345)
repl> `(a b ,(list 'c x) ,@(list x x x) ,@'(1 2 3 4))
=> (a b (c 12345) 12345 12345 12345 1 2 3 4)
g0dzill3r commented 1 year ago

Support for dotted pair splicing is in place:

repl> `(1 2 3 ,(+ 3 1) ,@(list 5))
=> (1 2 3 4 5)
repl> `(1 2 3 ,(+ 3 1) ,@5)
=> (1 2 3 4 . 5)
repl> `(1 2 3 ,(+ 3 1) ,@5 6 7)
java.lang.IllegalStateException: Illegal dotted pair in non-trailing position: 5
g0dzill3r commented 1 year ago

Escaping of escaping is not working properly. These should produce this output:

> `(1 `,(+ 1 ,(+ 2 3)) 4)
=> '(1 `,(+ 1 5) 4)

and

> `(1 ```,,@,,@(list (+ 1 2)) 4)
=> '(1 ```,,@,3 4)