Last active
November 5, 2015 04:47
-
-
Save dloscutoff/25873038e3e8eb057d61 to your computer and use it in GitHub Desktop.
Test cases for tinylisp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In 1: | |
() 42 (q(1 2 3)) | |
(q Here's;a:valid-name.]even[`though"it~has*special$chars&and#numb3rs!!) | |
( q (q x) ) | |
Out 1: | |
() | |
42 | |
(1 2 3) | |
Here's;a:valid-name.]even[`though"it~has*special$chars&and#numb3rs!! | |
(q x) | |
In 2: | |
(d x 42) (q x) x | |
(d y (q x)) y (v y) | |
(d self (q self)) self | |
(d L (q (L))) L | |
Out 2: | |
x | |
x | |
42 | |
y | |
x | |
42 | |
self | |
self | |
L | |
(L) | |
In 3: | |
(d minus-three (s 0 3)) | |
(d -3.0 (q minus-three)) | |
-3.0 | |
(v -3.0) | |
Out 3: | |
minus-three | |
-3.0 | |
minus-three | |
-3 | |
In 4: | |
(i 1 42 undefined-name) | |
(i 0 undefined-name 42) | |
Out 4: | |
42 | |
42 | |
In 5: | |
(d #1 42) | |
(d F | |
(q ( | |
(#1) | |
(G 15) | |
)) | |
) | |
(d G | |
(q ( | |
(#2) | |
(s #1 1) | |
)) | |
) | |
(F 6) | |
(d H | |
(q ( | |
(#1) | |
(s #1 1) | |
)) | |
) | |
(H 6) | |
(d I | |
(q ((#1) | |
((q ((#2) (s #1 #2))) 1) | |
)) | |
) | |
(I 6) | |
Out 5: | |
#1 | |
F | |
G | |
41 | |
H | |
5 | |
I | |
41 | |
In 6: | |
(d nil ()) | |
(d list (q (args args))) | |
(d lambda | |
(q (() | |
(params expr) | |
(list params expr) | |
)) | |
) | |
(d quote-each | |
(lambda (lyst) | |
(i lyst | |
(c | |
(list (q q) (h lyst)) | |
(quote-each (t lyst)) | |
) | |
nil | |
) | |
) | |
) | |
(d apply | |
(lambda (func arglist) | |
(v (c (q func) (quote-each arglist))) | |
) | |
) | |
(d map | |
(lambda (func lyst) | |
(i lyst | |
(c | |
(apply func (list (h lyst))) | |
(map func (t lyst)) | |
) | |
nil | |
) | |
) | |
) | |
(d partial | |
(lambda (func arg) | |
(list (q arglist) (list (q apply) (list (q q) func) (list (q c) arg (q arglist)))) | |
) | |
) | |
(map (partial s 0) (list 1 2 3 4)) | |
(d foldl* | |
(lambda (func lyst accum) | |
(i lyst | |
(foldl* func (t lyst) (apply func (list accum (h lyst)))) | |
accum | |
) | |
) | |
) | |
(d - | |
(lambda arglist | |
(i arglist | |
(i (t arglist) | |
(foldl* s (t arglist) (h arglist)) | |
(s 0 (h arglist)) | |
) | |
0 | |
) | |
) | |
) | |
(d + | |
(lambda arglist | |
(s 0 (apply - (c 0 arglist))) | |
) | |
) | |
(- 10 4 3 2) | |
(+ 1 2 3 4 5) | |
(d divides? | |
(lambda (factor int) | |
(i int | |
(i (l int factor) | |
0 | |
(divides? factor (s int factor)) | |
) | |
1 | |
) | |
) | |
) | |
(d prime?* | |
(lambda (int test-factor) | |
(i (l 1 test-factor) | |
(i (divides? test-factor int) | |
0 | |
(prime?* int (s test-factor 1)) | |
) | |
1 | |
) | |
) | |
) | |
(d prime? | |
(lambda (int) | |
(i (e int 1) | |
0 | |
(prime?* int (s int 1)) | |
) | |
) | |
) | |
(map prime? (list 1 2 3 4 5 23 10000)) | |
(d even? | |
(lambda (int) | |
(i int | |
(i (l int 0) | |
(even? (s 0 int)) | |
(odd? (s int 1)) | |
) | |
1 | |
) | |
) | |
) | |
(d odd? | |
(lambda (int) | |
(i int | |
(i (l int 0) | |
(odd? (s 0 int)) | |
(even? (s int 1)) | |
) | |
0 | |
) | |
) | |
) | |
(map even? (list 0 1 2 3 14 159 2653 58979 323846)) | |
Out 6: | |
nil | |
list | |
lambda | |
quote-each | |
apply | |
map | |
partial | |
(-1 -2 -3 -4) | |
foldl* | |
- | |
+ | |
1 | |
15 | |
divides? | |
prime?* | |
prime? | |
(0 1 1 0 1 1 0) | |
even? | |
odd? | |
(1 0 1 0 1 0 0 0 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment