File: eqp

package info (click to toggle)
scheme9 2025.08.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: lisp: 16,752; ansic: 11,869; sh: 806; makefile: 237; sed: 6
file content (38 lines) | stat: -rw-r--r-- 1,643 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
R4RS 6.2  (eq? object1 object2)  ==>  boolean

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, 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?.