Go provides top-level functions with a number of
interesting variations. Here are some of the features of Go functions,
both conventional and unusual
- Arguments are passed by value, including arrays and slices, though
passing a slice (by value) effectively passes the underlying array by
reference.
- Go functions need not return anything, making them like void functions
in C, they may return one value, or they may return multiple values.
- Return values may be named, much as parameters are.
Values assigned to the return value names are the values returned.
- The last parameter of a function may be declared to receive multiple
values as an array.
- Go provides anonymous functions which can be stored in variables.
- A function may make a “deferred,” call. The called function doesn't
run until after the calling (deferring?) function finishes. Intended for
cleanup.