code / tomo-koans

Lines447 Tomo432 INI9 Markdown6
(23 lines)
1 # Functions
3 func main()
5 # Functions can be declared in any order.
6 # The main() function is the first function to run,
7 # but it can call any other functions defined in
8 # the same file.
10 # Here, we're calling a function defined below.
11 # Fix up the function so it passes thes tests:
12 assert add(5, 10) == 15
13 assert add(2, 4) == 6
15 # Functions can also be called with keyword arguments:
16 assert add(x=4, y=12) == 16
18 # Functions are defined using `func` and must specify
19 # the types of their arguments and return values like this:
20 func add(x:Int, y:Int -> Int)
22 # Fix this so it returns a sensible result:
23 return ???