From 3b14186b70d52bba8255a71100a637effcebdf64 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 18 Feb 2025 21:53:32 -0600 Subject: [PATCH] sample-code: Add match_test.cl Demonstrates pattern matching --- sample-code/match_test.cl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 sample-code/match_test.cl diff --git a/sample-code/match_test.cl b/sample-code/match_test.cl new file mode 100644 index 0000000..179d178 --- /dev/null +++ b/sample-code/match_test.cl @@ -0,0 +1,18 @@ +//! This is a Conlang library demonstrating `match` + +struct Student { + name: str, + age: i32, +} + +fn Student (name: str, age: i32) -> Student { + Student: { name, age } +} + +fn match_test(student: Student) { + match student { + Student: { name: "shark", age } => println("Found a shark of ", age, " year(s)"), + Student: { name, age: 22 } => println("Found a 22-year-old named ", name), + Student: { name, age } => println("Found someone named ", name, " of ", age, " year(s)"), + } +}