Slide 14 of 37
func vs proc
func: cannot touch the caller's storage
func greet(name: Str): Str {
return "hey {name}!"
}
proc main(): void {
echo greet("ada")
}
proc: may hold a mutex
proc grow(vec: mut Str[dyn], tag: Str): void {
append(vec, tag)
}
proc main(): void {
mut Str[dyn] tags = ["bee"]
grow(tags, "hive")
echo tags
}
Both may perform I/O — echo, using, hive.net are all fine in either. The difference is what each may touch: a func cannot declare a mutex parameter (v: mut T) and cannot call a proc, so it can never write to storage its caller can see. A proc may do everything a func may, plus hold a mutex and call other procs. Programs start at proc main(): void. Nothing about the declaration says how a call runs — that is decided entirely at the call site.