[racket] struct equality?

From: Noel Welsh (noelwelsh at gmail.com)
Date: Mon Jul 5 08:39:28 EDT 2010

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.


Posted on the users mailing list.