diff --git a/examples/structs/structs.go b/examples/structs/structs.go index 268f65f..62d7cac 100644 --- a/examples/structs/structs.go +++ b/examples/structs/structs.go @@ -50,4 +50,15 @@ func main() { // Structs are mutable. sp.age = 51 fmt.Println(sp.age) + + // Structs don't always have to be defined as instances of types, + // you can define a struct anonymously. + dog := struct { + name string + isGood bool + }{ + "Rex", + true, + } + fmt.Println(dog) } diff --git a/examples/structs/structs.hash b/examples/structs/structs.hash index fe4d367..493e5b3 100644 --- a/examples/structs/structs.hash +++ b/examples/structs/structs.hash @@ -1,2 +1,2 @@ -f1dcc357b5e20c3aa3a97df8245efe4aea7940d6 -n7jt1x3iw4Z +5a15014159c5c98fe5f829c483ded3914db77053 +D9lW-Dd6XQP diff --git a/examples/structs/structs.sh b/examples/structs/structs.sh index 039fd00..3504330 100644 --- a/examples/structs/structs.sh +++ b/examples/structs/structs.sh @@ -6,4 +6,5 @@ $ go run structs.go &{Jon 42} Sean 50 -51 \ No newline at end of file +51 +{Rex true} diff --git a/public/structs b/public/structs index 84de85f..f57905f 100644 --- a/public/structs +++ b/public/structs @@ -43,7 +43,7 @@ records.

- +
package main
 
@@ -216,11 +216,32 @@ pointers are automatically dereferenced.

Structs are mutable.

- +
     sp.age = 51
     fmt.Println(sp.age)
+
+ + + + + +

Structs don’t always have to be defined as instances of types, +you can define a struct anonymously.

+ + + + +
+    dog := struct {
+        name   string
+        isGood bool
+    }{
+        "Rex",
+        true,
+    }
+    fmt.Println(dog)
 }
 
@@ -244,7 +265,8 @@ pointers are automatically dereferenced.

&{Jon 42} Sean 50 -51 +51 +{Rex true} @@ -263,7 +285,7 @@ pointers are automatically dereferenced.