From 804a2fe3c90c06a22a1eed5ea50d667ff3e7b08c Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Wed, 29 Jun 2022 21:52:30 -0700 Subject: Add pattern matching for record types. I like scheme because it's possible to add any convenient language feature I can think of. --- csc/match-test.csc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'csc/match-test.csc') diff --git a/csc/match-test.csc b/csc/match-test.csc index 31e7afa..c5314ce 100644 --- a/csc/match-test.csc +++ b/csc/match-test.csc @@ -85,3 +85,19 @@ (n (when (= 1 n)) 1) (n (when (= 10 n)) 2) (_ 3)))) + + +(define-match-record-type + (make-test-record-type a b c) + test-record-type? + %test-record-type + (a test-record-type-a) + (b test-record-type-b) + (c test-record-type-c)) + + +(test match-record-type + (assert-equal + 2 + (match (make-test-record-type 1 2 3) + ((% %test-record-type a b c) b)))) -- cgit v1.3.1