Functions

Go provides top-level functions with a number of interesting variations. Here are some of the features of Go functions, both conventional and unusual

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