aboutsummaryrefslogtreecommitdiff
path: root/examples/hello.halk
blob: 8b6b038595f958036e0b79c14ab0b52202383305 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
` comments in backticks `

` preprocessor directives `
#INCLUDE.'math', 'm';                                    ` bring the math library into scope, under the namespace 'm' ` 
#INCLUDE.'io', '';                                       ` bring the io library into global scope (with no namespace) `


str:hello = 'hello, ';                                   ` variables must be given a value at declaration `

int:PI = math/PI;                                        ` namespaces are accessed with a '/'' `

void:greeting. str:to = {                                ` functions declared the same way as variables, but with a . after 
                                                         the name, followed by arguments `

   str:message = strcat.hello, to;                       ` function application is right-associative `

   stdo.message;                                         ` since 'io' was brought into global scope, we
                                                         do not prefix it with a namespace/ `
}

int:sum_all. any[]:_  = {                                ` variadic functions are possible with the reserved '_' argument,
                                                         which is treated as an array `
   return.foldl.sum, 0, _;  
}

int:fibonacci. int:n = {
   if.(eq.n, 0), {
      return.1;
   }, {
      return.sum.
         (fibonacci.(sub.n, 1)),
         (fibonacci.(sub.n, 2));
   }
}

int:main. str[]:args = {                                 ` where code will begin executing `
   greeting.` comments can be placed *anywhere* `'world.';

   return.0;
}