V.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
So, your suggestion is, to have functions be comparable, but have the comparisons always be false (unless compared to nil)? How would that be useful and *not* completely confusing? e.g. how would that not lead to people asking here, once a week, why (os.Open == os.Open) == false or something like that?
On Wed, Nov 23, 2016 at 3:30 PM, T L <tapi...@gmail.com> wrote:
On Wednesday, November 23, 2016 at 9:53:57 PM UTC+8, Volker Dobler wrote:Just one argument out of many: Closures.x := 3f1 := func() int {return x}f2 := func() int { return 3 }// Is f1 == f2 ?x = 4// What now? Still f1 == f2? Or never equal?
Any bad to think then never equal?
V.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
-j
---j
So, even though two functions do completely different things, you still want to have them equal? And even though two other functions do completely the same thing, they should be different?
Can you give a good justification of that behavior? And do you really think it won't confuse people like hell?One of the main reasons given for not making functions comparable, is that there is no good, intuitive notion of what "equality" means in the face of inlining and closures, so *no matter what behavior you choose*, people will be confused.
On Wed, Nov 23, 2016 at 4:01 PM, T L <tapi...@gmail.com> wrote:
On Wednesday, November 23, 2016 at 10:39:01 PM UTC+8, Volker Dobler wrote:Am Mittwoch, 23. November 2016 15:30:39 UTC+1 schrieb T L:
On Wednesday, November 23, 2016 at 9:53:57 PM UTC+8, Volker Dobler wrote:Just one argument out of many: Closures.x := 3f1 := func() int {return x}f2 := func() int { return 3 }// Is f1 == f2 ?x = 4// What now? Still f1 == f2? Or never equal?
Any bad to think then never equal?That's basically is it: If functions are never equal so it isnot sensible make them comparable.V.
functions from the same declaration are equal.
and function variables at the same address are equal.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
-j
---j
---j
-j
On Wed, Nov 23, 2016 at 4:55 PM T L <tapi...@gmail.com> wrote:> But we can't take addresses of formally declared functions and function literals.Yes, so if you cannot have the function pointer (like in func foo() {}; fp := foo) then there is nothing to compare so I don't understand what's the connection to comparing of function pointers.
On Thursday, November 24, 2016 at 12:06:43 AM UTC+8, Jan Mercl wrote:On Wed, Nov 23, 2016 at 4:55 PM T L <tapi...@gmail.com> wrote:> But we can't take addresses of formally declared functions and function literals.Yes, so if you cannot have the function pointer (like in func foo() {}; fp := foo) then there is nothing to compare so I don't understand what's the connection to comparing of function pointers.
We cannot tabke addresses of constants too, but we can compare constants.
-j
If two functions do completely different things, they mus be two different functions.
Two different functions can also do the same thing, but they should be not equal.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
Ian, what you say is true, but is also true of types and other objects too, I think. I found some interesting anomalies playing around with the new plugin package.
Myself, I would have no objection to saying that two function values are equal if they are defined by the same source code and use no variables in outer non-global scopes. But I guess that would preclude certain compiler optimisations that pull in variables that happen to have known constant values.
I also wouldn't mind defining closure equality as undefined, but perhaps best to steer away from more undefined behaviour.
cheers,
rog.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
On Wed, Nov 23, 2016 at 4:30 PM, T L <tapi...@gmail.com> wrote:If two functions do completely different things, they mus be two different functions.No. An example has been given above, here is another one:Two different functions can also do the same thing, but they should be not equal.Why not? If someone who never read go code reads "f == g", why would they assume that this is your definition? Why wouldn't they get confused, that two functions who have the same definition (not "stem from the same declaration", but "contain the same code") are not equal?I agree that your definition is *consistent*. But it is still a) confusing for some cases and b) *not obviously the only sensible one*. Meaning, newcomers won't be able to infer from the expression, what it does. At all.(yes, go has similar problems elsewhere. But that doesn't mean, that we should pile on)
As you imply, the third idea in the form of “probabilistic equality” is generally unworkable. The computer risks forum is literally full of examples of failures here. A contrived example:
func a(x int) (int y) {
If x != 0 {
Y = 1/x
}
return
}
func a(x int) (int y) {
If x != 0 {
Y = 1/x
}
if x = 25638625386 {
y = 42 // model a rare bug
}
return
}
It would be a miracle if a behavioral tester found a difference here, as intel can attest. You can test every input or you can prove equality. Nothing else means equal.
How about “Idea Four”? If the functions needing equality testing are amenable to interfaces then build a HelloMyNameIs() function for each of them. If not suitable, perhaps reserved arguments could return an id that can be compared. Each of these are just examples of “the programmer knows so ask her”
It would be a miracle if a behavioral tester found a difference here, as intel can attest. You can test every input or you can prove equality. Nothing else means equal.
This is very nice! However, am i right in understanding that the magic is in knowing the text of the program--the fact that there are untaken branches? If so, this is not simply a 'behavioral' verification...it knows about the construction of the code and not just its behavior. Maybe I was unclear.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.