Skip to main content

rl_lang/docs/entries/concepts/arrays/
mod.rs

1use crate::docs::entry::{ConceptCategory, ConceptEntry, DescriptionEntry, DescriptionKind};
2
3pub static ARRAYS: ConceptEntry = ConceptEntry {
4    name: "arrays",
5    summary: "",
6    category: ConceptCategory::Syntax,
7    prerequisites: &[],
8    descriptions: &[
9        DescriptionEntry {
10            kind: DescriptionKind::Explanation,
11            title: None,
12            description: "declare a mutable array with `dec arr[<type>] <name> = [<items>]`",
13            examples: &[
14                "dec arr[int]   nums  = [1, 2, 3]",
15                "dec arr[string]   words = [\"hello\", \"world\"]",
16                "dec arr[float] vals  = [1.0, 2.0, 3.0]",
17                "dec arr[char]  chars = ['.', 'r', 'l']",
18                "dec arr[bool] bools = [true, false, true]",
19            ],
20            expected_output: &[],
21        },
22        DescriptionEntry {
23            kind: DescriptionKind::Explanation,
24            title: None,
25            description: "access an element by index with `arr[i]` zero-based",
26            examples: &[
27                "dec arr[int] nums = [10, 20, 30]\nprintln(nums[0])  // 10\nprintln(nums[2])  // 30",
28            ],
29            expected_output: &[],
30        },
31        DescriptionEntry {
32            kind: DescriptionKind::Explanation,
33            title: None,
34            description: "assign to an index with `arr[i] = value`",
35            examples: &[
36                "dec arr[int] nums = [1, 2, 3]\nnums[1] = 99\nprintln(nums)  // [1, 99, 3]",
37            ],
38            expected_output: &[],
39        },
40        DescriptionEntry {
41            kind: DescriptionKind::Explanation,
42            title: None,
43            description: "arrays are typed and all elements must be the same type",
44            examples: &[
45                "dec arr[int] nums = [1, 2, 3]\n// dec arr[int] bad = [1, \"two\"]  // error: type mismatch",
46            ],
47            expected_output: &[],
48        },
49        DescriptionEntry {
50            kind: DescriptionKind::Explanation,
51            title: None,
52            description: "nested arrays are supported",
53            examples: &["dec arr[arr[int]] matrix = [[1, 2], [3, 4]]\nprintln(matrix[0][1])  // 2"],
54            expected_output: &[],
55        },
56    ],
57    pitfalls: &[],
58    related: &[],
59    related_stdlib: &[],
60    since: None,
61};