Anonymous Functions

Back to Languages

Anonymous functions are function definitions that are not bound to an identifier.

It is syntactically lighter than a regular function, for one-time use functions.


Closures are a technique for implementing lexically scoped name binding in languages with first-class functions.

func intSeq() func() int {
    i := 0
    return func() int {
        i += 1
        return i

A function that returns another function that closes over the variable i to form a closure.