[plt-scheme] structures and equal?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Sep 24 07:51:14 EDT 2002

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



Posted on the users mailing list.