aboutsummaryrefslogtreecommitdiffstats
path: root/lispref
diff options
context:
space:
mode:
authorRichard M. Stallman2001-08-12 21:15:14 +0000
committerRichard M. Stallman2001-08-12 21:15:14 +0000
commita9749dabdf94b72b99a3adf3f1bbe88c12fffc31 (patch)
treed8b585ffe60af485f7dbd6ed435a2cc5a6bf41cd /lispref
parentfafee57973c1e467ee4233a9812e34c8187a0e71 (diff)
downloademacs-a9749dabdf94b72b99a3adf3f1bbe88c12fffc31.tar.gz
emacs-a9749dabdf94b72b99a3adf3f1bbe88c12fffc31.zip
Minor cleanups.
Diffstat (limited to 'lispref')
-rw-r--r--lispref/hash.texi53
-rw-r--r--lispref/lists.texi49
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
107anywhere else); if a particular value does get collected, the 107anywhere else); if a particular value does get collected, the
108corresponding association is removed from the hash table. 108corresponding association is removed from the hash table.
109 109
110If @var{weak} is @code{key-or-value}, associations are removed from the 110If @var{weak} is @code{key-or-value} or @code{t}, the hash table does
111hash table when either their key or their value part would be collected 111not protect either keys or values from garbage collection; if either
112as garbage, not counting references to the key and value from weak hash 112one is collected as garbage, the association is removed.
113tables. Likewise, if @var{weak} is @code{key-and-value}, associations 113
114are removed from the hash table when both their key and value would be 114If @var{weak} is @code{key-and-value}, associations are removed from
115collected as garbage, again not considering references to the key and 115the hash table when both their key and value would be collected as
116value from weak hash tables. 116garbage, again not considering references to the key and value from
117weak hash tables.
117 118
118The default for @var{weak} is @code{nil}, so that all keys and values 119The default for @var{weak} is @code{nil}, so that all keys and values
119referenced in the hash table are preserved from garbage collection. If 120referenced in the hash table are preserved from garbage collection. If
@@ -242,8 +243,24 @@ including negative integers.
242The specified functions are stored in the property list of @var{name} 243The specified functions are stored in the property list of @var{name}
243under the property @code{hash-table-test}; the property value's form is 244under 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
250This function returns a hash code for Lisp object @var{obj}.
251This is an integer which reflects the contents of @var{obj}
252and the other Lisp objects it points to.
253
254If 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
257If the two objects are not equal, the values returned by @code{sxhash}
258are usually different, but not always; but once in a rare while, by
259luck, you will encounter two distinct-looking objects that give the same
260result from @code{sxhash}.
261@end defun
245 262
246This example creates a hash table whose keys are strings that are 263 This example creates a hash table whose keys are strings that are
247compared case-insensitively. 264compared 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 280predefined test value @code{equal}. The keys can be any Lisp object,
265This function returns a hash code for Lisp object @var{obj}. 281and equal-looking objects are considered the same key.
266This is an integer which reflects the contents of @var{obj}
267and the other Lisp objects it points to.
268 282
269If 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
272If the two objects are not equal, the values returned by @code{sxhash} 286(make-hash-table :test 'contents-hash)
273are usually different, but not always; but once in a rare while, by 287@end example
274luck, you will encounter two distinct-looking objects that give the same
275result 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
387This function reruns the last link of the given @var{list}. The 387This 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
389null, @code{nil} is returned. If @var{n} is non-nil the 389null, @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.
496This macro provides an alternative way to write 496This 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}))}.
498It is new in Emacs 21. 498It 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)
505l
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
523This function creates a list of length @var{length}, in which all the 532This function creates a list of @var{length} elements, in which each
524elements have the identical value @var{object}. Compare 533element 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
1071x 1086x
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.}
1078x 1093x
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
1399value in the @sc{car} of the @sc{cdr} of the element. Here is an 1414value in the @sc{car} of the @sc{cdr} of the element. Here is an
1400example: 1415example 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
1553This function searches @var{alist} for a match for @var{key}. For each 1568This function searches @var{alist} for a match for @var{key}. For each
1554element of @var{alist}, it compares the element (if it is an atom) or 1569element of @var{alist}, it compares the element (if it is an atom) or
1555the element's @sc{car} (if it is a cons) against @var{key}, by calling 1570the 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
1624This function deletes from @var{alist} all the elements whose @sc{car} 1639This function deletes from @var{alist} all the elements whose @sc{car}
1625is @code{eq} to @var{key}. It returns the modified alist. 1640is @code{eq} to @var{key}. It returns @var{alist}, modified
1641in this way. Note that it modifies the original list structure
1642of @var{alist}.
1626 1643
1627@example 1644@example
1628(assq-delete-all 'foo 1645(assq-delete-all 'foo