From d7ead48d1fa7c6ffb32aeeb6f289bf859a6bbef8 Mon Sep 17 00:00:00 2001 From: James Baxter Date: Tue, 19 Aug 2014 12:06:02 +0100 Subject: Corrected the statement that rune is an alias for uint32 to say int32 --- go.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 656b1051..f7bd8ee3 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -78,7 +78,7 @@ func learnTypes() { can include line breaks.` // Same string type. // Non-ASCII literal. Go source is UTF-8. - g := 'Σ' // rune type, an alias for uint32, holds a unicode code point. + g := 'Σ' // rune type, an alias for int32, holds a unicode code point. f := 3.14195 // float64, an IEEE-754 64-bit floating point number. c := 3 + 4i // complex128, represented internally with two float64's. -- cgit v1.2.3 From a7a8c85257ee48b92913018a3c221a9703c6d59b Mon Sep 17 00:00:00 2001 From: Sam Zaydel Date: Sun, 10 Aug 2014 20:02:31 -0700 Subject: In golang slices are dynamic, so a mention of append() for slice updates seems to be appropriate. --- go.html.markdown | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index f7bd8ee3..390e36dc 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -101,6 +101,20 @@ can include line breaks.` // Same string type. var d2 [][]float64 // Declaration only, nothing allocated here. bs := []byte("a slice") // Type conversion syntax. + // Because they are dynamic, slices can be appended to on-demand. + // To append elements to a slice, built-in append() function is used. + // First argument is a slice to which we are appending. Commonly, + // the array variable is updated in place, as in example below. + s := []int{1, 2, 3} // Result is a slice of length 3. + s = append(s, 4, 5, 6) // Added 3 elements. Slice now has length of 6. + fmt.Println(s) // Updated slice is now [1 2 3 4 5 6] + // To append another slice, instead of list of atomic elements we can + // pass a reference to a slice or a slice literal like this, with a + // trailing elipsis, meaning take an array and unpack its elements, + // appending them to the slice. + s = append(s, []int{7, 8, 9}...) // Second argument is an array literal. + fmt.Println(s) // Updated slice is now [1 2 3 4 5 6 7 8 9] + p, q := learnMemory() // Declares p, q to be type pointer to int. fmt.Println(*p, *q) // * follows a pointer. This prints two ints. -- cgit v1.2.3 From 7000db24e040d712f963efa4dda70a9b3b99e3f8 Mon Sep 17 00:00:00 2001 From: Sam Zaydel Date: Sun, 10 Aug 2014 20:04:49 -0700 Subject: Fixed indentation error created in previous commit. --- go.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index 390e36dc..ddedd25e 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -107,13 +107,13 @@ can include line breaks.` // Same string type. // the array variable is updated in place, as in example below. s := []int{1, 2, 3} // Result is a slice of length 3. s = append(s, 4, 5, 6) // Added 3 elements. Slice now has length of 6. - fmt.Println(s) // Updated slice is now [1 2 3 4 5 6] - // To append another slice, instead of list of atomic elements we can + fmt.Println(s) // Updated slice is now [1 2 3 4 5 6] + // To append another slice, instead of list of atomic elements we can // pass a reference to a slice or a slice literal like this, with a // trailing elipsis, meaning take an array and unpack its elements, // appending them to the slice. s = append(s, []int{7, 8, 9}...) // Second argument is an array literal. - fmt.Println(s) // Updated slice is now [1 2 3 4 5 6 7 8 9] + fmt.Println(s) // Updated slice is now [1 2 3 4 5 6 7 8 9] p, q := learnMemory() // Declares p, q to be type pointer to int. fmt.Println(*p, *q) // * follows a pointer. This prints two ints. -- cgit v1.2.3 From 161e19baa96e3c9dbc5e8682cf3ef08bc6723a2e Mon Sep 17 00:00:00 2001 From: Sam Zaydel Date: Tue, 19 Aug 2014 20:43:18 -0700 Subject: Minor language change fixing mixed use of array and slice, where only slice is correct. --- go.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'go.html.markdown') diff --git a/go.html.markdown b/go.html.markdown index ddedd25e..c85209e0 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -110,9 +110,9 @@ can include line breaks.` // Same string type. fmt.Println(s) // Updated slice is now [1 2 3 4 5 6] // To append another slice, instead of list of atomic elements we can // pass a reference to a slice or a slice literal like this, with a - // trailing elipsis, meaning take an array and unpack its elements, - // appending them to the slice. - s = append(s, []int{7, 8, 9}...) // Second argument is an array literal. + // trailing elipsis, meaning take a slice and unpack its elements, + // appending them to slice s. + s = append(s, []int{7, 8, 9}...) // Second argument is a slice literal. fmt.Println(s) // Updated slice is now [1 2 3 4 5 6 7 8 9] p, q := learnMemory() // Declares p, q to be type pointer to int. -- cgit v1.2.3