- (eq? obj obj)procedure
Eq? is similar to eqv? except that in some cases it is capable of discerning distinctions finer than those detectable by eqv?.
Eq? and eqv? are guaranteed to have the same behavior on symbols, booleans, the empty list, pairs, procedures, and non-empty strings and vectors. Eq?'s behavior on numbers and characters is implementation-dependent, but it will always return either true or false, and will return true only when eqv? would also return true. Eq? may also behave differently from eqv? on empty vectors and empty strings.
(eq? 'a 'a) ===> #t (eq? '(a) '(a)) ===> unspecified (eq? (list 'a) (list 'a)) ===> #f (eq? "a" "a") ===> unspecified (eq? "" "") ===> unspecified (eq? '() '()) ===> #t (eq? 2 2) ===> unspecified (eq? #\A #\A) ===> unspecified (eq? car car) ===> #t (let ((n (+ 2 3))) (eq? n n)) ===> unspecified (let ((x '(a))) (eq? x x)) ===> #t (let ((x '#())) (eq? x x)) ===> #t (let ((p (lambda (x) x))) (eq? p p)) ===> #t
Rationale: It will usually be possible to implement eq? much more efficiently than eqv?, for example, as a simple pointer comparison instead of as some more complicated operation. One reason is that it may not be possible to compute eqv? of two numbers in constant time, whereas eq? implemented as pointer comparison will always finish in constant time. Eq? may be used like eqv? in applications using procedures to implement objects with state since it obeys the same constraints as eqv?.