aboutsummaryrefslogtreecommitdiffstats
path: root/test/match.scm
diff options
context:
space:
mode:
Diffstat (limited to 'test/match.scm')
-rw-r--r--test/match.scm14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/match.scm b/test/match.scm
new file mode 100644
index 0000000..db19be1
--- /dev/null
+++ b/test/match.scm
@@ -0,0 +1,14 @@
+; A Shape is either a Circle (w/ radius) or a Rectangle (w/ width/height)
+(def-type (Shape)
+ (Circle Float)
+ (Rectangle Float Float))
+
+; Return the area of s
+(define (area s)
+ (match s
+ (Rectangle w h) (* w h)
+ (Circle r) (* 3.14159 r)))
+
+(define s (Rectangle 3.0 4.0))
+
+(area s) \ No newline at end of file