sample-code: Add match_test.cl
Demonstrates pattern matching
This commit is contained in:
parent
a6ad20911d
commit
3b14186b70
18
sample-code/match_test.cl
Normal file
18
sample-code/match_test.cl
Normal file
@ -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)"),
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user