diff options
author | David Robillard <d@drobilla.net> | 2012-12-26 01:00:10 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-12-26 01:00:10 +0000 |
commit | 9d70db157eb9458f6716eacf24752fcfbb205fcb (patch) | |
tree | 203ff3cc1909ff5d471ea14e304289660a28565c | |
parent | c80b61512a905e46e52f43e01c531a3ac4b8aeb5 (diff) | |
download | resp-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.scm | 44 | ||||
-rw-r--r-- | wscript | 5 |
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)) @@ -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') |