rl_lang/docs/entries/concepts/match/
mod.rs1use crate::docs::entry::{ConceptCategory, ConceptEntry, DescriptionEntry, DescriptionKind};
2
3pub static MATCH: ConceptEntry = ConceptEntry {
4 name: "match",
5 summary: "branch on a value against literal patterns, with `_` as a catch-all",
6 descriptions: &[
7 DescriptionEntry {
8 kind: DescriptionKind::Syntax,
9 title: None,
10 description: "`match <value> { <pattern> => { <block> } ... }` runs the block whose pattern matches the value",
11 examples: &[
12 "match x {\n 1 => { println(\"one\") }\n 2 => { println(\"two\") }\n _ => { println(\"other\") }\n}",
13 ],
14 expected_output: &[],
15 },
16 DescriptionEntry {
17 kind: DescriptionKind::Explanation,
18 title: Some("wildcard arm"),
19 description: "`_` matches anything not caught by an earlier arm; without it, a value that matches no arm falls through silently",
20 examples: &[
21 "dec int x = 5\n\nmatch x {\n 1 => { println(\"one\") }\n _ => { println(\"something else\") }\n}",
22 ],
23 expected_output: &[],
24 },
25 DescriptionEntry {
26 kind: DescriptionKind::Pitfall,
27 title: None,
28 description: "each arm only matches a single literal value; there's no OR-pattern (`1 | 2 =>`) or variable binding yet, so ranges or destructuring need `if`/`elif` instead",
29 examples: &[],
30 expected_output: &[],
31 },
32 ],
33 category: ConceptCategory::ControlFlow,
34 prerequisites: &["control flow"],
35 pitfalls: &["arms only support literals and `_`, no OR-patterns or bindings"],
36 related: &["control flow"],
37 related_stdlib: &[],
38 since: None,
39};