The expression 'expression
is an abbreviation for (quote expression)
. When the expression is evaluated it evaluates to expression
as a data structure or atomic value. It's important to know that nothing in expression
gets evaluated further. Thus ''x
, which is (quote (quote x))
becomes the list (quote x)
.
eq?
is used to compare the same object. That means:
(eq? (list 'leet) (list 'leet)) ; ==> #f
Now both arguments look like (leet)
, but the two lists live in different memory locations in the computer and are thus not the same.
Constants like "string"
and '(some list)
might be created once and then referenced several times, but in a different implementation constants might be created newly for each location in the code. Thus:
(eq? "test" "test") ; ==> #t or #f
(eq? '(leet) '(leet)) ; ==> #t or #f
In your code you have excess '
so (first '('leet 'a 'f))
is actually the data (quote leet)
, a list with two symbols. Thus you are applying the exact same as the last expression above and you can expect #f
from some implementations and #t
from a few other. Comparing lists is not the same as comparing symbols.
So you can fix this by removing the extra '
. Then I assume you were not trying to make lists (quote leet)
.
(eq? (first '(leet a f)) (first '(leet coder a f f)))
; ==> #t
If you wanted to compare lists you should use equal?
:
(equal? (first '('leet 'a 'f)) (first '('leet 'coder 'a 'f 'f)))
; ==> #t
And know that (first '('leet 'a 'f))
in #lang racket
REPL prints ''leet
with two '
. The first '
is rackets funny way of printing values that evaluates to the value it should have printed, and perhaps the source of this confusion, and the second is the indicator that you have a list (quote leet)
, but many schemes abbreviate it to 'leet
.