This is a created article in which the information may have evolved or changed.
The go language supports anonymous functions, where functions can be passed or used like normal variables.
Use the following method
A: = func (input1 int) int{
return INPUT1 + = 1
}()
B: =a (2)
The anonymous function of the go language is closures, and the following is the explanation of closures in go language programming
Basic concepts
Closures are blocks of code that can contain variables that are free (not bound to specific objects) that are not within this block of code or
Defined in any global context, but in the context in which the code block is defined. The code block to execute (because the free variable contains
In the code block, so these free variables and the objects they refer to are not freed) to provide a binding calculation ring for the free variable
Environment (SCOPE).
The value of closures
The value of a closure is that it can be used as a function object or as an anonymous function, which means, for a type system, not only to represent
The data also represents the code. Most languages that support closures use functions as first-level objects, meaning that these functions can be stored in
Variables are passed as parameters to other functions, most importantly, they can be dynamically created and returned by the function.