[racket] clarification for beginners please

From: Alan Johnsey (a.johnsey at cox.net)
Date: Thu Apr 25 22:04:39 EDT 2013

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.

 

 

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

Posted on the users mailing list.