summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLevi Bostian <levi.bostian@gmail.com>2014-06-23 09:57:17 -0500
committerLevi Bostian <levi.bostian@gmail.com>2014-06-23 09:57:17 -0500
commit25973706867608f3218e606941a4f906f6dd3856 (patch)
treefefe8c21ca5cd313e449715d723554c0fa59c9c6
parentec800a5d148b0b1ae0c301ab4ddb72f0d6b9dede (diff)
parente881ba74f302cc5cac7f21cd1e7da163ca774d78 (diff)
Merge pull request #657 from szaydel/master
Golang - lack of information about named return values in functions
-rw-r--r--go.html.markdown10
1 files changed, 10 insertions, 0 deletions
diff --git a/go.html.markdown b/go.html.markdown
index bb6b04eb..c70f96bd 100644
--- a/go.html.markdown
+++ b/go.html.markdown
@@ -116,6 +116,16 @@ can include line breaks.` // Same string type.
learnFlowControl() // Back in the flow.
}
+// It is possible, unlike in many other languages for functions in go
+// to have named return values.
+// Assigning a name to the type being returned in the function declaration line
+// allows us to easily return from multiple points in a function as well as to
+// only use the return keyword, without anything further.
+func learnNamedReturns(x, y int) (z int) {
+ z = x * y
+ return // z is implicit here, because we named it earlier.
+}
+
// Go is fully garbage collected. It has pointers but no pointer arithmetic.
// You can make a mistake with a nil pointer, but not by incrementing a pointer.
func learnMemory() (p, q *int) {