Slide 15 of 37

First-class functions

A bare reference, and map
func double(n: Int): Int { return n * 2 }

proc main(): void {
	f := double
	echo "{f(21)} {map([1, 2, 3], double)}"
}
Partial application
func add(a: Int, b: Int): Int { return a + b }

proc main(): void {
	addFive := add(5, _)   // _ becomes the parameter
	echo addFive(10)
}
A callable is a value: a bare name on its own (f := takes) or a partial application with _ holes (handler(_, db)), each hole becoming a parameter in order. A func value may be used where a proc is expected, never the reverse. Three things cannot become values: a generic callable, one with a mutex parameter, and one with a statically-sized parameter beyond a single immutable binding.