[plt-scheme] equal? operator
Eli Barzilay schreef:
>On Nov 20, Hans Oesterholt-Dijkema wrote:
>
>
>>Is it possible to extend the equal? operator for new (structure)
>>types in mzscheme?
>>
>>
>
>If you need this for objects in your OO system, then why don't you
>implement your own equality predicate using the class system?
>(Especially given your reasons for why the standard solutions don't
>work.)
>
>
>
Hmm. I don't know If I follow you here. But no, I'm not interested in an
equal?
predicate for my OO system currently. I am interested in an equal?
predicate for
my datastruct library (sets, avl trees, etc).
>
>On Nov 20, Hans Oesterholt-Dijkema wrote:
>
>
>>Oh, and is it maybe also possible to extend eq? I'd like eq? to
>>work differently for persistent roos objects, comparing their Object
>>Identifiers instead of their "memory" locations.
>>
>>
>
>You don't want to do that! Making `eq?' do anything else is going to
>be confusing anyone who sees your code.
>
>
I do want to do this, because the semantics are right. Look here:
> (define store (list (list 2 3 4) (list 5 5 9)))
> (define (search n)
(define (in n L)
(if (null? L)
#f
(if (= n (car L))
#t
(in n (cdr L)))))
(define (f L)
(if (null? L)
#f
(if (in n (car L))
(car L)
(f (cdr L)))))
(f store))
>(define a (search 4))
>(define b (search 4))
>(eq? a b)
#t
Now the equivalent operation in Persistent ROOS
> (psearch (= (my-class my-attribute) 4))
(#roos #roos #roos)
> (define a (car (psearch (= (my-class my-attribute) 4))))
> a
#roos
> (define b (car (psearch (= (my-class my-attribute) 4))))
>b
#roos
> (eq? a b)
#f
> (peq? a b)
#t
Although the memory locations of the returned roos objects are different,
they are actually the same, in the backend system. The Object IDentifier
of a and b adhere (= a b).
Best whishes,
Hans
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20051121/37bc82fe/attachment.html>