[racket] Objects, Contracts, and Equality

From: Eric Dobson (endobson at cs.brown.edu)
Date: Sun Aug 22 21:01:07 EDT 2010

I am using the class system, and contracting objects. The
documentation says that objects (without implementing equal<%>) are
only equal? if they are eq?. My assumption was that when using equal?,
the contract-wrapper objects would look through to the base value and
compare them using equal? which would in turn use eq? (in the default
case). This does not seem to be the case, it appears that they are
still using eq? on the contracted values which leads to confusing
results. Is this the intended behavior?

-Eric

#lang racket

(provide (all-defined-out))

(define a (new object%))

(define/contract b
(object/c)
a)


(equal? a a) ;=> #t

(equal? a b) ;=> #f
(equal? b a) ;=> #f
(equal? b b) ;=> #f

(define c b)

(equal? c a) ;=> #f
(equal? c b) ;=> #f
(equal? c c) ;=> #t


Posted on the users mailing list.