rl_lang/docs/entries/tutorial/t1/
p9.rs1use crate::docs::entry::{ConceptCategory, ConceptEntry, DescriptionEntry, DescriptionKind};
2pub static STEP_ARRAYS: ConceptEntry = ConceptEntry {
3 name: "9. collecting data",
4 summary: "collecting data",
5 category: ConceptCategory::Types,
6 prerequisites: &[],
7 descriptions: &[
8 DescriptionEntry {
9 kind: DescriptionKind::Explanation,
10 title: None,
11 description: "an array holds multiple values of the same type in a sequence. you declare one with dec arr[type] and access elements by index starting from zero",
12 examples: &[
13 "dec arr[int] scores = [10, 20, 30]\n\nprintln(scores[0]) // 10\nprintln(scores[2]) // 30\n\nscores[1] = 99\nprintln(scores) // [10, 99, 30]",
14 ],
15 expected_output: &[],
16 },
17 DescriptionEntry {
18 kind: DescriptionKind::Explanation,
19 title: None,
20 description: "arr_push adds an element to the end and gives you back the updated array. arr_pop removes the last element. these are in std::array",
21 examples: &[
22 "get arr_push, arr_pop from std::array\n\ndec arr[int] nums = [1, 2, 3]\nnums = arr_push(nums, 4)\nprintln(nums) // [1, 2, 3, 4]\n\nnums = arr_pop(nums)\nprintln(nums) // [1, 2, 3]",
23 ],
24 expected_output: &[],
25 },
26 DescriptionEntry {
27 kind: DescriptionKind::Explanation,
28 title: None,
29 description: "len returns the number of elements in an array. arr_contains tells you if a value is in the array",
30 examples: &[
31 "get len, arr_contains from std::array\n\ndec arr[string] names = [\"ali\", \"sara\", \"omar\"]\nprintln(len(names)) // 3\nprintln(arr_contains(names, \"sara\")) // true",
32 ],
33 expected_output: &[],
34 },
35 DescriptionEntry {
36 kind: DescriptionKind::Explanation,
37 title: None,
38 description: "you can loop over an array with for ... in to visit every element",
39 examples: &[
40 "dec arr[int] guesses = [30, 60, 42]\n\nfor g in guesses {\n println(g)\n}\n// 30\n// 60\n// 42",
41 ],
42 expected_output: &[],
43 },
44 DescriptionEntry {
45 kind: DescriptionKind::Explanation,
46 title: None,
47 description: "exercise: track every guess the player makes in an array. at the end of the game print the full guess history\n\nexpected output:\n your guesses: [30, 60, 42]",
48 examples: &[
49 "get arr_push from std::array\nget read_int from std::io\nget concat from std::str\n\ndec arr[int] guesses = []\n\n// inside your game loop, after reading a guess:\n// guesses = arr_push(guesses, guess)\n\n// after the game:\nprintln(concat(\"your guesses: \", guesses))",
50 ],
51 expected_output: &[],
52 },
53 ],
54 pitfalls: &[],
55 related: &[],
56 related_stdlib: &[],
57 since: None,
58};