rl_lang/docs/entries/tutorial/t2/
p_a2.rs1use crate::docs::entry::{ConceptCategory, ConceptEntry, DescriptionEntry, DescriptionKind};
2
3pub static ADV_MODULES: ConceptEntry = ConceptEntry {
4 name: "2. splitting code across files",
5 summary: "splitting code across files",
6 category: ConceptCategory::Modules,
7 prerequisites: &[],
8 descriptions: &[
9 DescriptionEntry {
10 kind: DescriptionKind::Explanation,
11 title: None,
12 description: "you already know get from the beginner tutorial - you used it to import stdlib functions. the same keyword imports your own files. when you write get csv, rl looks for csv.rl in the same directory and runs it, making everything declared in it available",
13 examples: &[
14 "// main.rl\nget csv\n\n// now everything declared in csv.rl is available\n// csv_parse(...)\n// csv_serialize(...)\n// etc",
15 ],
16 expected_output: &[],
17 },
18 DescriptionEntry {
19 kind: DescriptionKind::Explanation,
20 title: None,
21 description: "you can also import specific names from a file using the from syntax. this is cleaner when you only need a few things",
22 examples: &[
23 "// import specific functions from csv.rl\nget csv_parse, csv_serialize from csv\n\n// or from a subdirectory\nget csv_parse from lib::csv",
24 ],
25 expected_output: &[],
26 },
27 DescriptionEntry {
28 kind: DescriptionKind::Explanation,
29 title: None,
30 description: "a file that is meant to be imported is just a regular .rl file with functions and constants declared at the top level. it should not have side effects - no println calls, no read calls, just declarations",
31 examples: &[
32 "// csv.rl - a library file\n// only declarations, no side effects\n\nCONST string DELIMITER = \";\"\n\nfn csv_parse(string raw) -> arr[arr[string]] {\n // ...\n}\n\nfn csv_serialize(arr[arr[string]] rows) -> string {\n // ...\n}",
33 ],
34 expected_output: &[],
35 },
36 DescriptionEntry {
37 kind: DescriptionKind::Explanation,
38 title: None,
39 description: "exercise: create two files. csv.rl with a single constant DELIMITER = \";\", and main.rl that imports csv.rl and prints the delimiter\n\nexpected output:\n delimiter is: ;",
40 examples: &[
41 "// csv.rl\nCONST string DELIMITER = \";\"\n\n// main.rl\nget csv\nget concat from std::str\n\nfn main() {\n println(concat(\"delimiter is: \", DELIMITER))\n}",
42 ],
43 expected_output: &[],
44 },
45 ],
46 pitfalls: &[],
47 related: &[],
48 related_stdlib: &[],
49 since: None,
50};