Skip to main content

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

1use crate::docs::entry::{ConceptCategory, ConceptEntry, DescriptionEntry, DescriptionKind};
2pub static STEP_IO: ConceptEntry = ConceptEntry {
3    name: "4. talking to the user",
4    summary: "talking to the user",
5    category: ConceptCategory::Tooling,
6    prerequisites: &[],
7    descriptions: &[
8        DescriptionEntry {
9            kind: DescriptionKind::Explanation,
10            title: None,
11            description: "so far your program only talks at the user. to make it interactive you need to read input. read waits for the user to type something and press enter, then gives you back what they typed as a string",
12            examples: &[
13                "get read from std::io\n\ndec string name = read(\"what is your name? \")\nprintln(\"hello \")\nprintln(name)",
14            ],
15            expected_output: &[],
16        },
17        DescriptionEntry {
18            kind: DescriptionKind::Explanation,
19            title: None,
20            description: "read_int and read_float do the same but convert the input to a number for you. use these when you expect the user to type a number",
21            examples: &[
22                "get read_int from std::io\n\ndec int age = read_int(\"how old are you? \")\nprintln(\"you are \")\nprintln(age)\nprintln(\" years old\")",
23            ],
24            expected_output: &[],
25        },
26        DescriptionEntry {
27            kind: DescriptionKind::Explanation,
28            title: None,
29            description: "to build nicer output you can use concat from std::str to join multiple values into one string before printing",
30            examples: &[
31                "get concat from std::str\n\ndec string name = \"Mohamed\"\ndec int    age  = 25\nprintln(concat(\"hello \", name, \", you are \", age, \" years old\"))",
32            ],
33            expected_output: &[],
34        },
35        DescriptionEntry {
36            kind: DescriptionKind::Explanation,
37            title: None,
38            description: "exercise: ask the player for a guess and echo it back. do not worry about checking if it is correct yet\n\nexpected output:\n  enter your guess: 50\n  you guessed: 50",
39            examples: &[
40                "get read_int from std::io\nget concat   from std::str\n\ndec int guess = read_int(\"enter your guess: \")\nprintln(concat(\"you guessed: \", guess))",
41            ],
42            expected_output: &[],
43        },
44    ],
45    pitfalls: &[],
46    related: &[],
47    related_stdlib: &[],
48    since: None,
49};