Add tests for macros
This commit is contained in:
parent
f2a481952d
commit
b2d6f21f88
|
@ -1,3 +1,5 @@
|
|||
|TranscendentalLisp.Macros||10:10:15 Mon, Mar 13, 2017|
|
||||
|TranscendentalLisp.MacroTests||10:07:00 Mon, Mar 13, 2017|
|
||||
|TranscendentalLisp.FinanceUnitTests||11:07:42 Thu, Mar 09, 2017|
|
||||
|TranscendentalLisp.LangUnitTests||11:04:17 Thu, Mar 09, 2017|
|
||||
|TranscendentalLisp.LexicalClosures||16:39:59 Tue, Mar 07, 2017|
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
Test
|
||||
---
|
||||
A simple macro example.
|
||||
|
||||
| script | lisp interpreter fixture |
|
||||
| check | evaluate text | (load "lisp/macro/nif.lisp") | T |
|
||||
| check | evaluate text | (nif 10 'p 'z 'n) | P |
|
||||
| check | evaluate text | (nif 0 'p 'z 'n) | Z |
|
||||
| check | evaluate text | (nif -2 'p 'z 'n) | N |
|
||||
| check | evaluate text | (nif (- 10 9) 'p 'z 'n) | P |
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
(defun plusp (n) (> n 0))
|
||||
(defun zerop (n) (= n 0))
|
||||
|
||||
(defmacro nif (expr pos zero neg)
|
||||
(let ((g (gensym)))
|
||||
`(let ((,g ,expr))
|
||||
(cond ((plusp ,g) ,pos)
|
||||
((zerop ,g) ,zero)
|
||||
(t ,neg)))))
|
|
@ -162,4 +162,11 @@ public class EVALTester {
|
|||
assertSExpressionsMatch(parseString("((1 2 3))"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void evalNestedBackquotesInList() {
|
||||
String input = "`(,`(1 ,`2 ,@`(3)))";
|
||||
|
||||
assertSExpressionsMatch(parseString("((1 2 3))"), evaluateString(input));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue