Literal and range patterns
Patterns can compare exact integer, boolean, or string literals. Integer ranges use half-open .. or inclusive ..= bounds. Strings can match a prefix, suffix, or contained part.
These are refutable patterns, so they belong in a match, conditional pattern, or a let with a divergent failure branch.
fn age_group(age: int) -> string {
match age { 13..=19 => "teen", _ => "other" }
}
fn kind(path: string) -> string {
match path { ..".zip" => "archive", _ => "other" }
}
fn main() {
println(age_group(16))
println(kind("notes.zip"))
}
Examples use the moon toolchain version shown beside each result.
Output & diagnostics
Expected: teen archive
Ctrl/⌘+Enter runs the current lesson.