diff options
| author | Paul Eggert | 2020-01-24 16:57:31 -0800 |
|---|---|---|
| committer | Paul Eggert | 2020-01-24 16:58:41 -0800 |
| commit | 7f5069850529f37e44939ce612e20d85be25af5c (patch) | |
| tree | cc085d23f0aa6d18ac2d20a66df990af642ac3b3 /doc/lispref/objects.texi | |
| parent | e5327a569c4db8f53b1497057bbac58f77330389 (diff) | |
| download | emacs-7f5069850529f37e44939ce612e20d85be25af5c.tar.gz emacs-7f5069850529f37e44939ce612e20d85be25af5c.zip | |
Improve doc of eq on bignums etc.
* doc/lispref/numbers.texi (Integer Basics):
* doc/lispref/objects.texi (Integer Type, Equality Predicates):
Be clearer about eq vs eql vs = on bignums, floats, and strings.
Diffstat (limited to 'doc/lispref/objects.texi')
| -rw-r--r-- | doc/lispref/objects.texi | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi index 4be2eb6918b..1c4e7e4d4e3 100644 --- a/doc/lispref/objects.texi +++ b/doc/lispref/objects.texi | |||
| @@ -266,8 +266,8 @@ but many machines provide a wider range. | |||
| 266 | Bignums can have arbitrary precision. Operations that overflow a | 266 | Bignums can have arbitrary precision. Operations that overflow a |
| 267 | fixnum will return a bignum instead. | 267 | fixnum will return a bignum instead. |
| 268 | 268 | ||
| 269 | Fixnums can be compared with @code{eq}, but bignums require | 269 | All numbers can be compared with @code{eql} or @code{=}; fixnums can |
| 270 | @code{eql} or @code{=}. To test whether an integer is a fixnum or a | 270 | also be compared with @code{eq}. To test whether an integer is a fixnum or a |
| 271 | bignum, you can compare it to @code{most-negative-fixnum} and | 271 | bignum, you can compare it to @code{most-negative-fixnum} and |
| 272 | @code{most-positive-fixnum}, or you can use the convenience predicates | 272 | @code{most-positive-fixnum}, or you can use the convenience predicates |
| 273 | @code{fixnump} and @code{bignump} on any object. | 273 | @code{fixnump} and @code{bignump} on any object. |
| @@ -2167,17 +2167,20 @@ appropriate chapter describing the data type. | |||
| 2167 | This function returns @code{t} if @var{object1} and @var{object2} are | 2167 | This function returns @code{t} if @var{object1} and @var{object2} are |
| 2168 | the same object, and @code{nil} otherwise. | 2168 | the same object, and @code{nil} otherwise. |
| 2169 | 2169 | ||
| 2170 | If @var{object1} and @var{object2} are fixnums with the same value, | 2170 | If @var{object1} and @var{object2} are symbols with the |
| 2171 | they are considered to be the same object (i.e., @code{eq} returns | ||
| 2172 | @code{t}). If @var{object1} and @var{object2} are symbols with the | ||
| 2173 | same name, they are normally the same object---but see @ref{Creating | 2171 | same name, they are normally the same object---but see @ref{Creating |
| 2174 | Symbols} for exceptions. For other types (e.g., lists, vectors, | 2172 | Symbols} for exceptions. For other non-numeric types (e.g., lists, vectors, |
| 2175 | strings), two arguments with the same contents or elements are not | 2173 | strings), two arguments with the same contents or elements are not |
| 2176 | necessarily @code{eq} to each other: they are @code{eq} only if they | 2174 | necessarily @code{eq} to each other: they are @code{eq} only if they |
| 2177 | are the same object, meaning that a change in the contents of one will | 2175 | are the same object, meaning that a change in the contents of one will |
| 2178 | be reflected by the same change in the contents of the other. | 2176 | be reflected by the same change in the contents of the other. |
| 2179 | For other types of objects whose contents cannot be changed (e.g., | 2177 | |
| 2180 | bignums and floats), two arguments with the same contents might or might not be | 2178 | If @var{object1} and @var{object2} are numbers with differing types or values, |
| 2179 | then they cannot be the same object and @code{eq} returns @code{nil}. | ||
| 2180 | If they are fixnums with the same value, | ||
| 2181 | then they are the same object and @code{eq} returns @code{t}. | ||
| 2182 | If they were computed separately but happen to have the same value | ||
| 2183 | and the same non-fixnum numeric type, then they might or might not be | ||
| 2181 | the same object, and @code{eq} returns @code{t} or @code{nil} | 2184 | the same object, and @code{eq} returns @code{t} or @code{nil} |
| 2182 | depending on whether the Lisp interpreter created one object or two. | 2185 | depending on whether the Lisp interpreter created one object or two. |
| 2183 | 2186 | ||
| @@ -2188,26 +2191,25 @@ depending on whether the Lisp interpreter created one object or two. | |||
| 2188 | @end group | 2191 | @end group |
| 2189 | 2192 | ||
| 2190 | @group | 2193 | @group |
| 2191 | (eq 456 456) | 2194 | (eq ?A ?A) |
| 2192 | @result{} t | 2195 | @result{} t |
| 2193 | @end group | 2196 | @end group |
| 2194 | 2197 | ||
| 2195 | @group | 2198 | @group |
| 2196 | (eq 3.0 3.0) | 2199 | (eq 3.0 3.0) |
| 2197 | @result{} t @r{or} nil | 2200 | @result{} t @r{or} nil |
| 2198 | ;; @r{The result is implementation-dependent.} | 2201 | ;; @r{Equal floats may or may not be the same object.} |
| 2199 | @end group | 2202 | @end group |
| 2200 | 2203 | ||
| 2201 | @group | 2204 | @group |
| 2202 | (eq "asdf" "asdf") | 2205 | (eq (make-string 3 ?A) (make-string 3 ?A)) |
| 2203 | @result{} nil | 2206 | @result{} nil |
| 2204 | @end group | 2207 | @end group |
| 2205 | 2208 | ||
| 2206 | @group | 2209 | @group |
| 2207 | (eq "" "") | 2210 | (eq "asdf" "asdf") |
| 2208 | @result{} t | 2211 | @result{} t @r{or} nil |
| 2209 | ;; @r{This exception occurs because Emacs Lisp} | 2212 | ;; @r{Equal string constants or may not be the same object.} |
| 2210 | ;; @r{makes just one multibyte empty string, to save space.} | ||
| 2211 | @end group | 2213 | @end group |
| 2212 | 2214 | ||
| 2213 | @group | 2215 | @group |