Skip to main content

rl_lang/docs/entries/tutorial/t1/
p3.rs

1use crate::docs::entry::{ConceptCategory, ConceptEntry, DescriptionEntry, DescriptionKind};
2pub static STEP_TYPES: ConceptEntry = ConceptEntry {
3    name: "3. types",
4    summary: "types",
5    category: ConceptCategory::Types,
6    prerequisites: &[],
7    descriptions: &[
8        DescriptionEntry {
9            kind: DescriptionKind::Explanation,
10            title: None,
11            description: "every value in rl has a type. the type tells rl what kind of data it is and what you can do with it. you already saw int, float, bool, string. here is what each one means",
12            examples: &[
13                "dec int    x = 42       // whole numbers, positive or negative\ndec float  y = 3.14     // numbers with a decimal point\ndec bool   b = true     // either true or false, nothing else\ndec string s = \"hello\"  // text, always in double quotes\ndec char   c = 'a'      // a single character, always in single quotes",
14            ],
15            expected_output: &[],
16        },
17        DescriptionEntry {
18            kind: DescriptionKind::Explanation,
19            title: None,
20            description: "rl will not let you mix types. assigning the wrong type is caught before your program even runs",
21            examples: &[
22                "dec int x = 10\n// x = \"hello\"  // error: expected int, got string\n// x = 3.14    // error: expected int, got float",
23            ],
24            expected_output: &[],
25        },
26        DescriptionEntry {
27            kind: DescriptionKind::Explanation,
28            title: None,
29            description: "byte is a special type for small unsigned integers from 0 to 255. plain number literals like 1, 42, 100 are bytes by default. they widen to int automatically when you assign them to an int variable",
30            examples: &[
31                "dec byte small = 200    // stays as byte\ndec int  big   = 200    // byte literal 200 widens to int\n\n// byte + byte = byte\n// byte + int  = int",
32            ],
33            expected_output: &[],
34        },
35        DescriptionEntry {
36            kind: DescriptionKind::Explanation,
37            title: None,
38            description: "exercise: look at your game variables from the previous step. what type should each one be? write a comment next to each variable explaining your choice",
39            examples: &[
40                "CONST int MAX_ATTEMPTS = 10   // int: whole number, no decimals needed\nCONST int MIN_NUMBER   = 1    // int: a position in a range\nCONST int MAX_NUMBER   = 100  // int: a position in a range\n\ndec int  secret_number = 42   // int: we compare it with guesses\ndec int  attempts_left = 10   // int: a counter we will decrease",
41            ],
42            expected_output: &[],
43        },
44    ],
45    pitfalls: &[],
46    related: &[],
47    related_stdlib: &[],
48    since: None,
49};