I am currently practicing the racket language and I ran into an interesting issue. I am trying to compare the elements of two lists. Normally if I compare two symbols, I'd get the following:
> (eq? 'leet 'leet)
#t
> (eq? 'let 'notleet)
#f
For some reason, when comparing the first element of two lists, I get false even though they're equal.
> (eq? (first '('leet 'a 'f)) (first '('leet 'coder 'a 'f 'f)))
#f
Why would that evaluate to false when I'm basically comparing the same two things?
Sylwester's answer is correct and detailed, but I want to bring out the TL/DR; here:
eq?. Instead, use equal?.Is this the whole story? No, of course not. But if you're looking for a one-liner to stick in your brain, it should be this one; equal? nearly always does what you want, and eq? often doesn't.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With