]> git.lizzy.rs Git - uwu-lang.git/blob - doc/syntax.md
aa62fb633cabf2387d23ff874a4bd98af187113b
[uwu-lang.git] / doc / syntax.md
1 ## Syntax
2
3 A module is made out of functions. Each function is made out of a name and exactly one expression, seperated by arbitrary whitespace.
4
5 ```
6 function_name expression
7
8 other_function_name
9         other_expression
10
11
12                 weird_indent_function_name
13
14         weird_indent_expression
15
16 ```
17
18 An expression is either of these:
19
20 - Integer literal: `0`, `1`, `3245`
21 - String literal: `"hello, world"`, `""`, ```"this is
22 a multiline
23 string literal
24 "```
25 - Argument number: `$0`, `$1`, `$5` 
26 - Function reference: `&function_name`
27 - Function call: `function_name(args)` or just `function_name`, where args is a comma-separated list of expressions.
28
29 **Important:** When passing arguments to a function, these arguments are not passed directly as values, but rather as expressions. Each argument is evaulated as the called function accesses it. This means that you can have constructs that would cause infinite recursion in other languages - a good example for a usecase of that are conditions: `:bool:if(condition, if_true, else)` is just a regular function from the standard library. `if_true` is only evaluated if condition is truey, meaning that if condition is falsey and `if_true` is a function call, that function will not be called.
30
31 Function name syntax:
32
33 - `function`: Call `function` in the current module.
34 - `path:to:module:function`: Call `function` in the module located at `path/to/module`. That path is relative to the path of the module calling the function. See module paths section under Invocation.
35 - `:std_module:function`: Call `function` in the module `std_module` from the standard library.