Skip to main content

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

1use crate::docs::entry::{ConceptCategory, ConceptEntry, DescriptionEntry, DescriptionKind};
2
3pub static OPERATORS: ConceptEntry = ConceptEntry {
4    name: "operators",
5    descriptions: &[
6        DescriptionEntry {
7            description: "arithmetic: `+`, `-`, `*`, `/`",
8            examples: &[
9                "dec int x = 10 + 5   // 15",
10                "dec int y = 10 - 3   // 7",
11                "dec int z = 4  * 3   // 12",
12                "dec int w = 10 / 2   // 5",
13            ],
14            kind: DescriptionKind::Explanation,
15            title: None,
16            expected_output: &[],
17        },
18        DescriptionEntry {
19            description: "comparison: `==`, `!=`, `<`, `<=`, `>`, `>=` and always return bool",
20            examples: &[
21                "5 == 5    // true",
22                "5 != 3    // true",
23                "3 < 10    // true",
24                "10 >= 10  // true",
25            ],
26            kind: DescriptionKind::Explanation,
27            title: None,
28            expected_output: &[],
29        },
30        DescriptionEntry {
31            description: "logical: `!`",
32            examples: &["!true           // false"],
33            kind: DescriptionKind::Explanation,
34            title: None,
35            expected_output: &[],
36        },
37        DescriptionEntry {
38            description: "unary negation with `-`",
39            examples: &["dec int x = 5\ndec int y = -x  // -5"],
40            kind: DescriptionKind::Explanation,
41            title: None,
42            expected_output: &[],
43        },
44        DescriptionEntry {
45            description: "method-style call with `.` - calls a function with the value as first argument",
46            examples: &[
47                "get std::str::to_upper\n\ndec string s = \"hello\"\ns.to_upper()  // \"HELLO\"",
48                "get std::array::arr_push\n\ndec arr[int] nums = [1, 2]\nnums = nums.arr_push(3)  // [1, 2, 3]",
49            ],
50            kind: DescriptionKind::Explanation,
51            title: None,
52            expected_output: &[],
53        },
54        DescriptionEntry {
55            description: "grouping with `()` controls evaluation order",
56            examples: &["dec int x = (2 + 3) * 4  // 20\ndec int y = 2 + 3 * 4    // 14"],
57            kind: DescriptionKind::Explanation,
58            title: None,
59            expected_output: &[],
60        },
61    ],
62    summary: "",
63    category: ConceptCategory::Syntax,
64    prerequisites: &[],
65    pitfalls: &[],
66    related: &[],
67    related_stdlib: &[],
68    since: None,
69};