chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] define-struct and equality


From: Zbigniew
Subject: Re: [Chicken-users] define-struct and equality
Date: Sun, 24 Jun 2007 22:40:53 -0500

Carlos,

'point' is represented internally as a 3-element vector, tagged as a
structure type.  Slot (element) 0 is the symbol 'point.  Slots 1 and 2
are for the x and y values, respectively.  You can therefore use
equal? to compare two records.  equal? also compares the slots
recursively as expected, so

(equal? (make-point (make-point 1 2) (make-point 3 4))
       (make-point (make-point 1 2) (make-point 3 4)))
; => #t.

On 6/24/07, Carlos Pita <address@hidden> wrote:
Hi all,

is there any warranty regarding equality and records? Experimentally I got:

#;62> (define-record point x y)
#;63> (define p1 (make-point 1 1))
#;64> (define p2 (make-point 1 1))
#;65> (equal? p1 p2)
#t
#;66> (eq? p1 p2)
#f
#;68> (eqv? p1 p2)
#f

So by-value equality seems to work between different record instances with
equal field values, but I'm not sure that I can infer that from this
example.
Should I define my own equality predicate?

Thank you in advance
Cheers,
Carlos

_______________________________________________
Chicken-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/chicken-users






reply via email to

[Prev in Thread] Current Thread [Next in Thread]