[racket] clarification for beginners please

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Apr 25 22:29:50 EDT 2013

Opaque structures are inaccessible to all operations, including equality. That's why only (eq? z y) can succeed because z and y point to the same object and eq? compares the pointers not the objects. 

This opacity is needed to ensure the integrity of values created by the core (lambdas) and by macros (classes), which are essentially all structures. 

-- Matthias




On Apr 25, 2013, at 10:04 PM, Alan Johnsey wrote:

> I’ve followed this discussion and thought I understood it quite well until I tried it. Following are my results, using Racket 3.3 on Windows XP:
>  
> Test 1:
>  
> #lang racket
> (define-struct posn (x y))
> (define x (make-posn 4 5))
> (define y (make-posn 4 5))
> (define z y)
>  
> > (equal? x y)
> #f
> > (eq? x y)
> #f
> > (eqv? x y)
> #f
> > (equal? x z)
> #f
> > (equal? y z)
> #t
> > (eq? x z)
> #f
> > (eq? y z)
> #t
>  
> Contrary to my understanding of what several commenters have said
> equal? eq? and eqv? all give #f when comparing x & y
> equal? and eq? both give #t when comparing y & z
>  
> Test 2:
>  
> #lang racket
> (define-struct posn (x y) #:transparent)
> (define x (make-posn 4 5))
> (define y (make-posn 4 5))
> (define z y)
>  
> > (equal? x y)
> #t
> > (eq? x y)
> #f
> > (equal? x z)
> #t
>  
> Adding #:transparent to the posn struct definition makes x equal? to both y and z as it should, and eq? gives #f when comparing x and y as it should.
>  
>  
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130425/ebb0c1ad/attachment.html>

Posted on the users mailing list.