Skip to content

Commit a98a2f8

Browse files
committed
Function Documentation
1 parent 66544ef commit a98a2f8

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

docs/functions.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,53 @@
1-
## This Page Is A Work In Progress
1+
Functions in Mastermind work more like templates/macros, as they do not perform any passing by value. All functions are essentially inlined at compile time. This means multiple calls to a large function will significantly increase your compiled code size.
2+
3+
Functions are created using the def command followed by the function name and a list of typed arguments inside of
4+
( ).
5+
6+
Functions currently do not support return values since they function as marcos and will instead just update the value of variables passed in
7+
8+
```
9+
def quote(cell arg) {
10+
output 39; // ASCII single quote
11+
output arg;
12+
output 39;
13+
}
14+
15+
cell N = 'g';
16+
quote<N>;
17+
N += 3;
18+
quote<N>;
19+
//OUTPUT
20+
// 'g''j'
21+
```
22+
23+
When Structs are used in conjunction with Functions you are allowed to define multiple functions with the same name and it
24+
will use the input to perform function overloading.
25+
26+
```
27+
struct test {
28+
cell value;
29+
}
30+
31+
def quote(struct test structarg) {
32+
output 34; // ASCII double quote
33+
output structarg.value;
34+
output 34;
35+
}
36+
37+
def quote(cell arg) {
38+
output 39; // ASCII single quote
39+
output arg;
40+
output 39;
41+
}
42+
43+
struct test A;
44+
a.value = 'p';
45+
quote<A>;
46+
cell N = 'g';
47+
quote<N>;
48+
N += 3;
49+
quote<N>;
50+
51+
//OUTPUT
52+
// "p"'g''j'
53+
```

0 commit comments

Comments
 (0)