Go Concepts - Functions: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 23: Line 23:


</pre>
</pre>
Examples:


<pre>
<pre>
func add(a int, b int) (int) {
  return a + b;
}
</pre>
</pre>



Revision as of 21:54, 17 March 2016

External

Internal

Overview

Syntax

func <name>([parameter-identifier1] [type1], [parameter-identifier2] [type2], ...) ([return-type1], [return-type2], ...) {

   statement1
   statemen2
   ...

   return <return-value1>, <return-value2>

}

Examples:

func add(a int, b int) (int) {
   return a + b;
}

Built-in Functions

Closures

Anonymous function that capture local variables.

More about closures is available here.