diff --git a/examples/slices/slices.go b/examples/slices/slices.go index 541b582..49a69a9 100644 --- a/examples/slices/slices.go +++ b/examples/slices/slices.go @@ -5,7 +5,8 @@ package main import ( "fmt" - "slices" + + "golang.org/x/exp/slices" ) func main() { @@ -26,6 +27,7 @@ func main() { // as an additional parameter to `make`. s = make([]string, 3) fmt.Println("emp:", s, "len:", len(s), "cap:", cap(s)) + fmt.Printf("Slice Address: %p\n", s) // We can set and get just like with arrays. s[0] = "a" @@ -36,6 +38,7 @@ func main() { // `len` returns the length of the slice as expected. fmt.Println("len:", len(s)) + fmt.Printf("Slice s Address: %p\n", s) // In addition to these basic operations, slices // support several more that make them richer than @@ -46,6 +49,7 @@ func main() { s = append(s, "d") s = append(s, "e", "f") fmt.Println("apd:", s) + fmt.Printf("Slice s Address: %p\n", s) // Slices can also be `copy`'d. Here we create an // empty slice `c` of the same length as `s` and copy @@ -53,20 +57,24 @@ func main() { c := make([]string, len(s)) copy(c, s) fmt.Println("cpy:", c) + fmt.Printf("Slice c Address: %p\n", c) // Slices support a "slice" operator with the syntax // `slice[low:high]`. For example, this gets a slice // of the elements `s[2]`, `s[3]`, and `s[4]`. l := s[2:5] fmt.Println("sl1:", l) + fmt.Printf("Slice l Address: %p\n", l) // This slices up to (but excluding) `s[5]`. l = s[:5] fmt.Println("sl2:", l) + fmt.Printf("Slice l Address: %p\n", l) // And this slices up from (and including) `s[2]`. l = s[2:] fmt.Println("sl3:", l) + fmt.Printf("Slice l Address: %p\n", l) // We can declare and initialize a variable for slice // in a single line as well. diff --git a/go.mod b/go.mod index 1f29711..9ac6942 100644 --- a/go.mod +++ b/go.mod @@ -21,4 +21,5 @@ require ( github.com/aws/aws-sdk-go-v2/service/sts v1.7.0 // indirect github.com/aws/smithy-go v1.8.0 // indirect github.com/dlclark/regexp2 v1.10.0 // indirect + golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect ) diff --git a/go.sum b/go.sum index 4917b64..82a3214 100644 --- a/go.sum +++ b/go.sum @@ -34,6 +34,7 @@ github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cn github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= @@ -42,6 +43,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ= +golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=