diff options
-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') |