jfs.world (103) [Avatar] Offline
#1
2.37: s/defaultMatch/defaultMatcher

2.38: it's not so much the listing that's a problem, but the explanation that's the problem. It's not because you're calling the method via an interface type that's the problem, it's because of the assignment, because the assignment ("var matcher Matcher = something") is a copy operation, and if you have a pointer-receiver method, there's no way to modify the original "dm" if "var matcher Matcher = dm"....
Bill Kennedy (68) [Avatar] Offline
#2
That assignment is not a copy operation. I do a much better job describing this in chapter 5 (coming soon). The value of the concrete type is "embedded" in the interface value. If there is a pointer receiver, the value will be shared.
jfs.world (103) [Avatar] Offline
#3
Bill Kennedy wrote:That assignment is not a copy operation. I do a much better job describing this in chapter 5 (coming soon). The value of the concrete type is "embedded" in the interface value. If there is a pointer receiver, the value will be shared.


thanks, Bill. Do you mean a new version of chapter 5?

About the copy operation, that's how I think of it, coming from a C background. That's how I see

var matcher Matcher = dm


as being different from

var matcher Matcher = &dm


and why the latter works but not the former, because in the latter, the address is copied to 'matcher' (and 'matcher' thus becomes a pointer). If the first assignment is not a copy ("copy by value" to be more exact), I don't see why you shouldn't be able to get access to the original 'dm' struct through 'matcher'. Or are we maybe talking about the same thing, but using different terminology?

Short demo program to illustrate how the first assignment only produces a copy that's different from the original struct: http://play.golang.org/p/FSuCsMee8J
Bill Kennedy (68) [Avatar] Offline
#4
Yes, the new chapter 5 will explain all of this to you. I hope for it to be ready this week. Once it is, I will send you a special copy. Send me an email to bill@ardanstudios.com