2f386b7b411c6fb68748e0a266616efb01675109 — kotrunga 2 months ago 042d299
Added 1.3.12, and more notes delineating the differences between slices and arrays
A basics/structs-slices-maps/1.3.12_nil-slices.go => basics/structs-slices-maps/1.3.12_nil-slices.go +18 -0
@@ 0,0 1,18 @@
+ /*
+ 	Notes 1.3.12
+ 
+ 	- The zero value of a slice is nil
+ 	- A nil slice has a length and capacity of 0, and has no underlying array
+ */
+ 
+ package main
+ 
+ import "fmt"
+ 
+ func main() {
+ 	var s []int
+ 	fmt.Println(s, len(s), cap(s))
+ 	if s == nil {
+ 		fmt.Println("nil!")
+ 	}
+ }< 
\ No newline at end of file

M basics/structs-slices-maps/1.3.6_array.go => basics/structs-slices-maps/1.3.6_array.go +4 -1
@@ 1,7 1,10 @@ /*
  	Notes 1.3.6
  
- 	- In Go, an array's length is part of it's type
+ 	- In Go, an array's length is part of it's type.
+ 		This is important; it means that two arrays, [4]int and [5]int are
+ 		distinct and incompatible types
+ 	- Arrays do not need to be initialized explicitly; the element values are 0
  */
  
  package main

M basics/structs-slices-maps/1.3.7_slices.go => basics/structs-slices-maps/1.3.7_slices.go +4 -2
@@ 5,6 5,8 @@ - Slices are more common than arrays in practice
  	- Specify a slice like this: a[low : high]
  		It excludes the end (high)
+ 	- The difference between arrays and slices when declared are subtle;
+ 	  if there is a size specified, it's an array. 
  */
  
  package main


@@ 12,8 14,8 @@ import "fmt"
  
  func main() {
- 	primes := [6]int{2, 3, 5, 7 , 11, 13}
+ 	primes := [6]int{2, 3, 5, 7 , 11, 13}	// This is an array
  
- 	var s []int = primes[1:4]	// selects [3, 5, 7] from primes
+ 	var s []int = primes[1:4]	// This is a slice. Selects [3, 5, 7] from primes.
  	fmt.Println(s)
  }= 
\ No newline at end of file