Skip to main content

rl_lang/docs/entries/concepts/functions/
mod.rs

1use crate::docs::entry::{ConceptCategory, ConceptEntry, DescriptionEntry, DescriptionKind};
2
3pub static FUNCTIONS: ConceptEntry = ConceptEntry {
4    name: "functions",
5    descriptions: &[
6        DescriptionEntry {
7            description: "declare a function with `fn <name>(<type> <param>, ...) { <body> }`",
8            examples: &["fn greet(string name) {\n    println(name)\n}\n\ngreet(\"Mohamed\")"],
9            kind: DescriptionKind::Explanation,
10            title: None,
11            expected_output: &[],
12        },
13        DescriptionEntry {
14            description: "specify a return type with `-> <type>` and use `return` to return a value",
15            examples: &[
16                "fn add(int a, int b) -> int {\n    return a + b\n}\n\ndec int res = add(3, 4)  // 7",
17            ],
18            kind: DescriptionKind::Explanation,
19            title: None,
20            expected_output: &[],
21        },
22        DescriptionEntry {
23            description: "functions are first-class values and can be stored in variables",
24            examples: &[
25                "fn double(int x) -> int {\n    return x * 2\n}\n\ndec fn f = double\nprintln(f(5))  // 10",
26            ],
27            kind: DescriptionKind::Explanation,
28            title: None,
29            expected_output: &[],
30        },
31    ],
32    summary: "",
33    category: ConceptCategory::Syntax,
34    prerequisites: &[],
35    pitfalls: &[],
36    related: &[],
37    related_stdlib: &[],
38    since: None,
39};