aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-12-26 01:00:10 +0000
committerDavid Robillard <d@drobilla.net>2012-12-26 01:00:10 +0000
commit9d70db157eb9458f6716eacf24752fcfbb205fcb (patch)
tree203ff3cc1909ff5d471ea14e304289660a28565c
parentc80b61512a905e46e52f43e01c531a3ac4b8aeb5 (diff)
downloadresp-9d70db157eb9458f6716eacf24752fcfbb205fcb.tar.gz
resp-9d70db157eb9458f6716eacf24752fcfbb205fcb.tar.bz2
resp-9d70db157eb9458f6716eacf24752fcfbb205fcb.zip
Add cond macro test.
git-svn-id: http://svn.drobilla.net/resp/trunk@448 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r--test/cond.scm44
-rw-r--r--wscript5
2 files changed, 48 insertions, 1 deletions
diff --git a/test/cond.scm b/test/cond.scm
new file mode 100644
index 0000000..6151ef2
--- /dev/null
+++ b/test/cond.scm
@@ -0,0 +1,44 @@
+(define-syntax let
+ (syntax-rules ()
+ ((let ((name val) ...) body1 body2 ...)
+ ((lambda (name ...) body1 body2 ...)
+ val ...))))
+
+(define-syntax begin
+ (syntax-rules ()
+ ((begin exp ...)
+ ((lambda () exp ...)))))
+
+(define-syntax cond
+ (syntax-rules (else =>)
+ ((cond (else result1 result2 ...))
+ (begin result1 result2 ...))
+ ((cond (test => result))
+ (let ((temp test))
+ (if temp (result temp))))
+ ((cond (test => result) clause1 clause2 ...)
+ (let ((temp test))
+ (if temp
+ (result temp)
+ (cond clause1 clause2 ...))))
+ ((cond (test)) test)
+ ((cond (test) clause1 clause2 ...)
+ (let ((temp test))
+ (if temp
+ temp
+ (cond clause1 clause2 ...))))
+ ((cond (test result1 result2 ...))
+ (if test (begin result1 result2 ...)))
+ ((cond (test result1 result2 ...)
+ clause1 clause2 ...)
+ (if test
+ (begin result1 result2 ...)
+ (cond clause1 clause2 ...)))))
+
+(define x 2)
+
+(cond
+ ((= x 1) 1.0)
+ ((= x 2) 2.0)
+ ((= x 3) 3.0)
+ (else 42.0))
diff --git a/wscript b/wscript
index 4607155..18cf82c 100644
--- a/wscript
+++ b/wscript
@@ -114,8 +114,11 @@ def test(ctx):
# Closures
run_test('./test/closure.scm', '6 : Int')
run_test('./test/noargs.scm', '6 : Int')
+
+ # Derived expressions
run_test('./test/let.scm', '42 : Int')
-
+ run_test('./test/cond.scm', '2.00000 : Float')
+
# Algebraic data types
run_test('./test/match.scm', '12.0000 : Float')