aboutsummaryrefslogtreecommitdiff
path: root/examples/hello.halk
blob: 6e5f7bfeaec110d4e034dd361b65e9d9d015e807 (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
` comments in backticks `

#inc# #somefile.halk#   ` include a file `
#inc# #stdio#           ` include the 'stdio' header (file path stored in the macro #stdio#) `

:str:hello = "Hello";                                    ` define a variable 'hello' with the type 'str' `

:str:greet.:str:target = strcat.hello, ", ", target;     ` define a function 'greet' that returns a 'str' and accepts an 
                                                         argument 'target', also of type 'str' `

` some more functions `
:void:add1. :int:n = n = +. n, 1;
:int:fac.:int:n=if.(==.n,0),1,*.n,fac.-.n,1;

:int:fib. :int:n = if. (<=. n, 1),                       ` multiple lines can be used for clarity ` 
                       n,
                       +. fib.(-. n, 1), fib. -. n, 2);


:void:print_greet.:str:target = stdio/pln.greet.target;  ` namespaces `

:namespace:people = {                                    ` create namespace `
   struct.person, :int:age, :str:name;                   ` create a struct -- syntax not finalized `
   
   :str:person_report. :struct:person = {
      :str:age = int->str.person.age;
      :str:name = person.name;

      strcat. "NAME:\t", name, "\nAGE:\t", age;
   }

   :void:person_birthday. :struct:person = {
      stdio/pln. "Happy birthday, ", person.name;
      person.age = +.person.age, 1;
   }
}