[plt-scheme] structures and equal?
At Mon, 23 Sep 2002 20:59:28 -0400, "Pedro Pinto" wrote:
> I am trying to compare two instances of a simple structure for
> value equality.
> Thus:
>
> (define-struct location (x y))
>
> (equal? (make-location 0 0) (make-location 0 0))
> #f
>
> (eq? (make-location 0 0) (make-location 0 0))
> #f
>
> (eqv? (make-location 0 0) (make-location 0 0))
> #f
The short answer is that changing the definition to
(define-struct location (x y) (make-inspector))
will solve your problem.
The `(make-inspector)' expression creates a new inspector that is under
the current inspector. Consequently, when `equal?' is used later with
the current inspector, `equal?' is allowed to see into `location'
structures and compare them for equality.
Matthew