[racket] struct equality?

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Mon Jul 5 15:42:38 EDT 2010

On Mon, Jul 5, 2010 at 8:39 AM, Noel Welsh <noelwelsh at gmail.com> wrote:
> Maybe this will help:
>
> racket@> (module a racket (struct foo (a b) #:transparent) (define
> make-a-foo foo) (provide make-a-foo))
> racket@> (module b racket (struct foo (a b) #:transparent) (define
> make-b-foo foo) (provide make-b-foo))
> racket@> (require 'a 'b)
> racket@> (make-a-foo 1 2)
> (foo 1 2)
> racket@> (make-b-foo 1 2)
> (foo 1 2)
> racket@> (equal? (make-a-foo 1 2) (make-b-foo 1 2))
> #f
>
> Or this:
>
> racket@> (struct foo (a b))
> racket@> (define foo1 (foo 1 2))
> racket@> (struct foo (a b))
> racket@> (define foo2 (foo 1 2))
> racket@> (equal? foo1 foo2)
> #f
> racket@> (foo-a foo1)
> foo-a: expects args of type <struct:foo>; given instance of a
> different <struct:foo>
>
>  === context ===
> /Users/noel/programming/plt/collects/racket/private/misc.rkt:74:7
>
>
> On Mon, Jul 5, 2010 at 2:34 AM, Todd O'Bryan <toddobryan at gmail.com> wrote:
>> OK, this is harder than I thought. The struct is defined at the top
>> level, so under what conditions might it be re-defined?
>
> Loading the file twice, I guess.
>
>> Also, will an accessor of the form struct-name-field work with any
>> struct of name struct-name, or does it only work with structs that are
>> in the same scope?
>
> Probably what you mean by "same scope", though scope isn't really the
> issue here.
>
> N.
>
See, that's the weird thing. I have a struct with two fields and I can do:

> (equal? (foo-one x) (foo-one y))
#t
> (equal? (foo-two x) (foo-two y))
#t
> (equal? x y)
#f

Suggesting that they are, in fact, the same kinds of structs, and that
something more subtle (where subtle means annoying) is going on.

Ah, well. I'm not going to have a chance to look at the code until
tomorrow evening anyway. If anyone has a flash of insight, feel free
to share.

Todd


Posted on the users mailing list.