rl_lang/docs/entries/tutorial/t1/
p2.rs1use crate::docs::entry::{ConceptCategory, ConceptEntry, DescriptionEntry, DescriptionKind};
2pub static STEP_VARIABLES: ConceptEntry = ConceptEntry {
3 name: "2. storing values",
4 summary: "storing values",
5 category: ConceptCategory::Types,
6 prerequisites: &[],
7 descriptions: &[
8 DescriptionEntry {
9 kind: DescriptionKind::Explanation,
10 title: None,
11 description: "a variable is a named box that holds a value. you declare one with dec, then its type, then its name, then its value. rl needs to know the type upfront and it never changes",
12 examples: &[
13 "dec int score = 0\ndec string name = \"Mohamed\"\ndec bool active = true\ndec float ratio = 1.5",
14 ],
15 expected_output: &[],
16 },
17 DescriptionEntry {
18 kind: DescriptionKind::Explanation,
19 title: None,
20 description: "once declared you can read a variable by name, and reassign it with =",
21 examples: &["dec int lives = 3\nprintln(lives) // 3\n\nlives = 2\nprintln(lives) // 2"],
22 expected_output: &[],
23 },
24 DescriptionEntry {
25 kind: DescriptionKind::Explanation,
26 title: None,
27 description: "for numbers you can use += -= *= /= to update a variable in place instead of writing the full reassignment",
28 examples: &[
29 "dec int score = 0\nscore += 10 // score is now 10\nscore += 5 // score is now 15\nscore -= 3 // score is now 12\nprintln(score) // 12",
30 ],
31 expected_output: &[],
32 },
33 DescriptionEntry {
34 kind: DescriptionKind::Explanation,
35 title: None,
36 description: "constants are like variables but they can never be reassigned. declare with CONST. by convention use UPPER_CASE names",
37 examples: &[
38 "CONST int MAX_SCORE = 100\nCONST string LANG = \"rl\"\n\nprintln(MAX_SCORE) // 100\n// MAX_SCORE = 200 // error: cannot assign to constant",
39 ],
40 expected_output: &[],
41 },
42 DescriptionEntry {
43 kind: DescriptionKind::Explanation,
44 title: None,
45 description: "exercise: store the game configuration in variables and constants. the secret number will come from random later, so use a placeholder for now\n\nexpected output:\n secret number is: 42\n you have 10 attempts",
46 examples: &[
47 "CONST int MAX_ATTEMPTS = 10\nCONST int MIN_NUMBER = 1\nCONST int MAX_NUMBER = 100\n\ndec int secret_number = 42 // placeholder until we learn random\ndec int attempts_left = MAX_ATTEMPTS\n\nprintln(\"secret number is: \") // just for testing\nprintln(secret_number)\nprintln(\"you have \")\nprintln(attempts_left)\nprintln(\"attempts\")",
48 ],
49 expected_output: &[],
50 },
51 ],
52 pitfalls: &[],
53 related: &[],
54 related_stdlib: &[],
55 since: None,
56};