On May 3, 2022, at 7:27 PM, Ian Lance Taylor <i...@golang.org> wrote: > > Does a program like this print true or false? > > func F() func() int { return func() int { return 0 } } > func G() { fmt.Println(F() == F()) } > > What about a program like this: > > func H(i int) func() *int { return func() *int { return &i } } > func J() { fmt.Println(H(0) == H(1)) }
Note that in Scheme eq? works for functions as one would expect. > (define (f (lambda (x) x)) > (eq? f f)) => #t > (define g f) > (eq? f g) => #t But > (eq? f (lambda (x) x)) => #f > (define g (lambda () (lambda (x) x))) > (eq? (g) (g)) => #f One can make the case that each closure would be a fresh instance. This is more clear with a slightly more complex version: (define (counter m) (let ((n m) (lambda () (set! n (+ n 1)) n)) And equal? is unspecified in the Scheme RnRS but would typically implemented to return #f. > (equal? (lambda (x) x) (lambda (x) x)) => #f Technically (lambda (x) x) & (lambda (y) y) behave identically but proving the more general case of this in even an interpreter would be hard to impossible. Go pretty much has the same considerations (but for a more complex data model). -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/2E7C1835-40C5-4FF3-BB7B-D32A71EE89EC%40iitbombay.org.