Add tests for macros

This commit is contained in:
Mike Cifelli 2017-03-13 10:15:05 -04:00
parent f2a481952d
commit b2d6f21f88
4 changed files with 30 additions and 0 deletions

View File

@ -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|

View File

@ -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 |

9
lisp/macro/nif.lisp Normal file
View File

@ -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)))))

View File

@ -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));
}
}