forked from luna/jorts
26 lines
662 B
Text
26 lines
662 B
Text
import io
|
|
|
|
// takes a function that receives two ints, returns an int
|
|
// Func is the function type keyword, to not switch it with fn (which declares
|
|
// a function)
|
|
fn function_tester (Func func ([int, int] -> int)) -> int {
|
|
func(2, 2)
|
|
}
|
|
|
|
fn add(int a, int b) -> int {
|
|
a + b
|
|
}
|
|
|
|
fn main () {
|
|
// passes the function add to function_tester
|
|
res := function_tester(add)
|
|
|
|
// you can also create functions and put them in variables. not putting a
|
|
// function name on the fn block makes it return a Func instance to be put
|
|
// in a variable
|
|
anonymous := (fn () {})
|
|
|
|
// anonymous has type Func ([] -> void)
|
|
|
|
io.puts("res = {res}")
|
|
}
|