On 11/13/2019 10:11 PM, Andrew wrote:
I have this:

(define (related? a1 a2)
   (if (equal? a1 a2)
       true
       (related? (member (rest ("proc that calls list" a1)) (rest ("proc that calls 
list" a2)))
          (member a1 ("proc that calls list" a2))))))


a1 and a2 are part of a binary search tree and I have another function that 
creates a list from the elements of the tree

hence the "proc that calls list"


For some reason, whatever input I'm putting into a1 and a2 is returning only 
true, even when I know the answer is suppose to be false

Can anyone guide me onto what's going wrong?


Just guessing, but the empty list is a member of both and all instances of '() compare eq?  (same symbol).

   (eq? (list) (list))
   => #t

But if I'm understanding your code correctly, it seems like it would not work for lists of different lengths.

I think it would be simpler - and probably faster - to create an (obj -> obj)  hash^[1]   using eq? compare from the elements of one list and step though the other list checking if the current element is in the hash.   Or skip the lists entirely and do it directly from the tree walks.

Hope this helps,
George

[1] https://docs.racket-lang.org/reference/hashtables.html?q=hash#%28def._%28%28quote._~23~25kernel%29._hasheq%29%29

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/ce899707-40ca-8f36-2841-3670b41e5b74%40comcast.net.

Reply via email to