@kjk1/

book value methods

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.49061668961032856","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgImZtdCIKCi8vIDpzaG93IHN0YXJ0CnR5cGUgRm9vIHN0cnVjdCB7CglCYXIgaW50Cn0KCmZ1bmMgKGYgRm9vKSBJbmNyZW1lbnQoKSB7CglmLkJhcisrCn0KCmZ1bmMgbWFpbigpIHsKCXZhciBwICpGb28KCgkvLyBDYWxsaW5nIGBwLkluY3JlbWVudGAgaXMgYXV0b21hdGljYWxseSBjaGFuZ2VkIHRvIGAoKnApLkluY3JlbWVudGAgYnkgdGhlIGNvbXBpbGVyLgoJLy8gKE5vdGUgdGhhdCBgKnBgIGlzIGdvaW5nIHRvIHJlbWFpbiBhdCAwIGJlY2F1c2UgYSBjb3B5IG9mIGAqcGAsIGFuZCBub3QgdGhlIG9yaWdpbmFsIGAqcGAgYXJlIGJlaW5nIGVkaXRlZCkKCXAgPSAmRm9ve30KCWZtdC5QcmludGYoIigqcCkuQmFyIGlzICVkXG4iLCAoKnApLkJhcikKCXAuSW5jcmVtZW50KCkKCWZtdC5QcmludGYoIigqcCkuQmFyIGlzICVkXG4iLCAoKnApLkJhcikKCgkvLyBBcyB5b3UgY2FuIHNlZSwgY2FsbGluZyBgKCpwKS5JbmNyZW1lbnRgIGRpcmVjdGx5IGRvZXMgdGhlIHNhbWUgdGhpbmcuCglwID0gJkZvb3t9CglmbXQuUHJpbnRmKCIoKnApLkJhciBpcyAlZFxuIiwgKCpwKS5CYXIpCgkoKnApLkluY3JlbWVudCgpCglmbXQuUHJpbnRmKCIoKnApLkJhciBpcyAlZFxuIiwgKCpwKS5CYXIpCn0KCi8vIDpzaG93IGVuZA=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main

import "fmt"

// :show start
type Foo struct {
	Bar int
}

func (f Foo) Increment() {
	f.Bar++
}

func main() {
	var p *Foo

	// Calling `p.Increment` is automatically changed to `(*p).Increment` by the compiler.
	// (Note that `*p` is going to remain at 0 because a copy of `*p`, and not the original `*p` are being edited)
	p = &Foo{}
	fmt.Printf("(*p).Bar is %d\n", (*p).Bar)
	p.Increment()
	fmt.Printf("(*p).Bar is %d\n", (*p).Bar)

	// As you can see, calling `(*p).Increment` directly does the same thing.
	p = &Foo{}
	fmt.Printf("(*p).Bar is %d\n", (*p).Bar)
	(*p).Increment()
	fmt.Printf("(*p).Bar is %d\n", (*p).Bar)
}

// :show end