diff options
| author | Richard M. Stallman | 2001-08-12 21:15:14 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2001-08-12 21:15:14 +0000 |
| commit | a9749dabdf94b72b99a3adf3f1bbe88c12fffc31 (patch) | |
| tree | d8b585ffe60af485f7dbd6ed435a2cc5a6bf41cd /lispref | |
| parent | fafee57973c1e467ee4233a9812e34c8187a0e71 (diff) | |
| download | emacs-a9749dabdf94b72b99a3adf3f1bbe88c12fffc31.tar.gz emacs-a9749dabdf94b72b99a3adf3f1bbe88c12fffc31.zip | |
Minor cleanups.
Diffstat (limited to 'lispref')
| -rw-r--r-- | lispref/hash.texi | 53 | ||||
| -rw-r--r-- | lispref/lists.texi | 49 |
2 files changed, 65 insertions, 37 deletions
diff --git a/lispref/hash.texi b/lispref/hash.texi index 3f4e4380be6..4b12160c603 100644 --- a/lispref/hash.texi +++ b/lispref/hash.texi | |||
| @@ -107,13 +107,14 @@ values from being collected as garbage (if they are not referenced | |||
| 107 | anywhere else); if a particular value does get collected, the | 107 | anywhere else); if a particular value does get collected, the |
| 108 | corresponding association is removed from the hash table. | 108 | corresponding association is removed from the hash table. |
| 109 | 109 | ||
| 110 | If @var{weak} is @code{key-or-value}, associations are removed from the | 110 | If @var{weak} is @code{key-or-value} or @code{t}, the hash table does |
| 111 | hash table when either their key or their value part would be collected | 111 | not protect either keys or values from garbage collection; if either |
| 112 | as garbage, not counting references to the key and value from weak hash | 112 | one is collected as garbage, the association is removed. |
| 113 | tables. Likewise, if @var{weak} is @code{key-and-value}, associations | 113 | |
| 114 | are removed from the hash table when both their key and value would be | 114 | If @var{weak} is @code{key-and-value}, associations are removed from |
| 115 | collected as garbage, again not considering references to the key and | 115 | the hash table when both their key and value would be collected as |
| 116 | value from weak hash tables. | 116 | garbage, again not considering references to the key and value from |
| 117 | weak hash tables. | ||
| 117 | 118 | ||
| 118 | The default for @var{weak} is @code{nil}, so that all keys and values | 119 | The default for @var{weak} is @code{nil}, so that all keys and values |
| 119 | referenced in the hash table are preserved from garbage collection. If | 120 | referenced in the hash table are preserved from garbage collection. If |
| @@ -242,8 +243,24 @@ including negative integers. | |||
| 242 | The specified functions are stored in the property list of @var{name} | 243 | The specified functions are stored in the property list of @var{name} |
| 243 | under the property @code{hash-table-test}; the property value's form is | 244 | under the property @code{hash-table-test}; the property value's form is |
| 244 | @code{(@var{test-fn} @var{hash-fn})}. | 245 | @code{(@var{test-fn} @var{hash-fn})}. |
| 246 | @end defun | ||
| 247 | |||
| 248 | @tindex sxhash | ||
| 249 | @defun sxhash obj | ||
| 250 | This function returns a hash code for Lisp object @var{obj}. | ||
| 251 | This is an integer which reflects the contents of @var{obj} | ||
| 252 | and the other Lisp objects it points to. | ||
| 253 | |||
| 254 | If two objects @var{obj1} and @var{obj2} are equal, then @code{(sxhash | ||
| 255 | @var{obj1})} and @code{(sxhash @var{obj2})} are the same integer. | ||
| 256 | |||
| 257 | If the two objects are not equal, the values returned by @code{sxhash} | ||
| 258 | are usually different, but not always; but once in a rare while, by | ||
| 259 | luck, you will encounter two distinct-looking objects that give the same | ||
| 260 | result from @code{sxhash}. | ||
| 261 | @end defun | ||
| 245 | 262 | ||
| 246 | This example creates a hash table whose keys are strings that are | 263 | This example creates a hash table whose keys are strings that are |
| 247 | compared case-insensitively. | 264 | compared case-insensitively. |
| 248 | 265 | ||
| 249 | @example | 266 | @example |
| @@ -258,22 +275,16 @@ compared case-insensitively. | |||
| 258 | 275 | ||
| 259 | (make-hash-table :test 'case-fold) | 276 | (make-hash-table :test 'case-fold) |
| 260 | @end example | 277 | @end example |
| 261 | @end defun | ||
| 262 | 278 | ||
| 263 | @tindex sxhash | 279 | Here is how you could define a hash table test equivalent to the |
| 264 | @defun sxhash obj | 280 | predefined test value @code{equal}. The keys can be any Lisp object, |
| 265 | This function returns a hash code for Lisp object @var{obj}. | 281 | and equal-looking objects are considered the same key. |
| 266 | This is an integer which reflects the contents of @var{obj} | ||
| 267 | and the other Lisp objects it points to. | ||
| 268 | 282 | ||
| 269 | If two objects @var{obj1} and @var{obj2} are equal, then @code{(sxhash | 283 | @example |
| 270 | @var{obj1})} and @code{(sxhash @var{obj2})} are the same integer. | 284 | (define-hash-table-test 'contents-hash 'equal 'sxhash) |
| 271 | 285 | ||
| 272 | If the two objects are not equal, the values returned by @code{sxhash} | 286 | (make-hash-table :test 'contents-hash) |
| 273 | are usually different, but not always; but once in a rare while, by | 287 | @end example |
| 274 | luck, you will encounter two distinct-looking objects that give the same | ||
| 275 | result from @code{sxhash}. | ||
| 276 | @end defun | ||
| 277 | 288 | ||
| 278 | @node Other Hash | 289 | @node Other Hash |
| 279 | @section Other Hash Table Functions | 290 | @section Other Hash Table Functions |
diff --git a/lispref/lists.texi b/lispref/lists.texi index b0a3a1f6b85..5f16394ae12 100644 --- a/lispref/lists.texi +++ b/lispref/lists.texi | |||
| @@ -384,7 +384,7 @@ If @var{n} is zero or negative, @code{nthcdr} returns all of | |||
| 384 | @end defun | 384 | @end defun |
| 385 | 385 | ||
| 386 | @defun last list &optional n | 386 | @defun last list &optional n |
| 387 | This function reruns the last link of the given @var{list}. The | 387 | This function returns the last link of @var{list}. The |
| 388 | @code{car} of this link is the list's last element. If @var{list} is | 388 | @code{car} of this link is the list's last element. If @var{list} is |
| 389 | null, @code{nil} is returned. If @var{n} is non-nil the | 389 | null, @code{nil} is returned. If @var{n} is non-nil the |
| 390 | @var{n}-th-to-last link is returned instead, or the whole @var{list} if | 390 | @var{n}-th-to-last link is returned instead, or the whole @var{list} if |
| @@ -496,6 +496,15 @@ any symbol can serve both purposes. | |||
| 496 | This macro provides an alternative way to write | 496 | This macro provides an alternative way to write |
| 497 | @code{(setq @var{listname} (cons @var{newelt} @var{listname}))}. | 497 | @code{(setq @var{listname} (cons @var{newelt} @var{listname}))}. |
| 498 | It is new in Emacs 21. | 498 | It is new in Emacs 21. |
| 499 | |||
| 500 | @example | ||
| 501 | (setq l '(a b)) | ||
| 502 | @result{} (a b) | ||
| 503 | (push 'c l) | ||
| 504 | @result{} (c a b) | ||
| 505 | l | ||
| 506 | @result{} (c a b) | ||
| 507 | @end example | ||
| 499 | @end defmac | 508 | @end defmac |
| 500 | 509 | ||
| 501 | @defun list &rest objects | 510 | @defun list &rest objects |
| @@ -520,9 +529,9 @@ are given, the empty list is returned. | |||
| 520 | @end defun | 529 | @end defun |
| 521 | 530 | ||
| 522 | @defun make-list length object | 531 | @defun make-list length object |
| 523 | This function creates a list of length @var{length}, in which all the | 532 | This function creates a list of @var{length} elements, in which each |
| 524 | elements have the identical value @var{object}. Compare | 533 | element is @var{object}. Compare @code{make-list} with |
| 525 | @code{make-list} with @code{make-string} (@pxref{Creating Strings}). | 534 | @code{make-string} (@pxref{Creating Strings}). |
| 526 | 535 | ||
| 527 | @example | 536 | @example |
| 528 | @group | 537 | @group |
| @@ -533,6 +542,12 @@ elements have the identical value @var{object}. Compare | |||
| 533 | (make-list 0 'pigs) | 542 | (make-list 0 'pigs) |
| 534 | @result{} nil | 543 | @result{} nil |
| 535 | @end group | 544 | @end group |
| 545 | @group | ||
| 546 | (setq l (make-list 3 '(a b)) | ||
| 547 | @result{} ((a b) (a b) (a b)) | ||
| 548 | (eq (car l) (cadr l)) | ||
| 549 | @result{} t | ||
| 550 | @end group | ||
| 536 | @end example | 551 | @end example |
| 537 | @end defun | 552 | @end defun |
| 538 | 553 | ||
| @@ -1064,19 +1079,19 @@ value. | |||
| 1064 | 1079 | ||
| 1065 | @example | 1080 | @example |
| 1066 | @group | 1081 | @group |
| 1067 | (setq x '(1 2 3 4)) | 1082 | (setq x '(a b c)) |
| 1068 | @result{} (1 2 3 4) | 1083 | @result{} (a b c) |
| 1069 | @end group | 1084 | @end group |
| 1070 | @group | 1085 | @group |
| 1071 | x | 1086 | x |
| 1072 | @result{} (1 2 3 4) | 1087 | @result{} (a b c) |
| 1073 | (nreverse x) | 1088 | (nreverse x) |
| 1074 | @result{} (4 3 2 1) | 1089 | @result{} (c b a) |
| 1075 | @end group | 1090 | @end group |
| 1076 | @group | 1091 | @group |
| 1077 | ;; @r{The cons cell that was first is now last.} | 1092 | ;; @r{The cons cell that was first is now last.} |
| 1078 | x | 1093 | x |
| 1079 | @result{} (1) | 1094 | @result{} (a) |
| 1080 | @end group | 1095 | @end group |
| 1081 | @end example | 1096 | @end example |
| 1082 | 1097 | ||
| @@ -1379,9 +1394,9 @@ the value @code{cones}; the key @code{oak} is associated with | |||
| 1379 | 1394 | ||
| 1380 | @example | 1395 | @example |
| 1381 | @group | 1396 | @group |
| 1382 | '((pine . cones) | 1397 | ((pine . cones) |
| 1383 | (oak . acorns) | 1398 | (oak . acorns) |
| 1384 | (maple . seeds)) | 1399 | (maple . seeds)) |
| 1385 | @end group | 1400 | @end group |
| 1386 | @end example | 1401 | @end example |
| 1387 | 1402 | ||
| @@ -1397,10 +1412,10 @@ the alist element: | |||
| 1397 | 1412 | ||
| 1398 | Sometimes it is better to design an alist to store the associated | 1413 | Sometimes it is better to design an alist to store the associated |
| 1399 | value in the @sc{car} of the @sc{cdr} of the element. Here is an | 1414 | value in the @sc{car} of the @sc{cdr} of the element. Here is an |
| 1400 | example: | 1415 | example of such an alist: |
| 1401 | 1416 | ||
| 1402 | @example | 1417 | @example |
| 1403 | '((rose red) (lily white) (buttercup yellow)) | 1418 | ((rose red) (lily white) (buttercup yellow)) |
| 1404 | @end example | 1419 | @end example |
| 1405 | 1420 | ||
| 1406 | @noindent | 1421 | @noindent |
| @@ -1549,7 +1564,7 @@ becomes clearer if the association is written in dotted pair notation: | |||
| 1549 | @end smallexample | 1564 | @end smallexample |
| 1550 | @end defun | 1565 | @end defun |
| 1551 | 1566 | ||
| 1552 | @defun assoc-default key alist test default | 1567 | @defun assoc-default key alist &optional test default |
| 1553 | This function searches @var{alist} for a match for @var{key}. For each | 1568 | This function searches @var{alist} for a match for @var{key}. For each |
| 1554 | element of @var{alist}, it compares the element (if it is an atom) or | 1569 | element of @var{alist}, it compares the element (if it is an atom) or |
| 1555 | the element's @sc{car} (if it is a cons) against @var{key}, by calling | 1570 | the element's @sc{car} (if it is a cons) against @var{key}, by calling |
| @@ -1622,7 +1637,9 @@ the associations of one copy without affecting the other: | |||
| 1622 | @defun assq-delete-all key alist | 1637 | @defun assq-delete-all key alist |
| 1623 | @tindex assq-delete-all | 1638 | @tindex assq-delete-all |
| 1624 | This function deletes from @var{alist} all the elements whose @sc{car} | 1639 | This function deletes from @var{alist} all the elements whose @sc{car} |
| 1625 | is @code{eq} to @var{key}. It returns the modified alist. | 1640 | is @code{eq} to @var{key}. It returns @var{alist}, modified |
| 1641 | in this way. Note that it modifies the original list structure | ||
| 1642 | of @var{alist}. | ||
| 1626 | 1643 | ||
| 1627 | @example | 1644 | @example |
| 1628 | (assq-delete-all 'foo | 1645 | (assq-delete-all 'foo |