aboutsummaryrefslogtreecommitdiffstats
path: root/doc/lispref/symbols.texi
diff options
context:
space:
mode:
authorMattias EngdegÄrd2024-02-17 13:27:25 +0100
committerMattias EngdegÄrd2024-02-17 20:29:54 +0100
commit1b20fe7dff234a8660d8a73c9a183c19863331a7 (patch)
tree9de544f8c0e489d5320761dab55c581d5085deed /doc/lispref/symbols.texi
parent934046990b5cbe48d863559d3d1f9c07d7dd949a (diff)
downloademacs-scratch/obarray.tar.gz
emacs-scratch/obarray.zip
Update NEWS and manual after obarray changesscratch/obarray
* doc/lispref/abbrevs.texi (Abbrev Tables): * doc/lispref/symbols.texi (Creating Symbols): * doc/lispref/objects.texi (Type Predicates): Update text for obarray now being an opaque type. * etc/NEWS: Announce.
Diffstat (limited to 'doc/lispref/symbols.texi')
-rw-r--r--doc/lispref/symbols.texi59
1 files changed, 21 insertions, 38 deletions
diff --git a/doc/lispref/symbols.texi b/doc/lispref/symbols.texi
index e95e53d972d..5adf69fa9db 100644
--- a/doc/lispref/symbols.texi
+++ b/doc/lispref/symbols.texi
@@ -177,34 +177,18 @@ know how Lisp reads them. Lisp must ensure that it finds the same
177symbol every time it reads the same sequence of characters in the same 177symbol every time it reads the same sequence of characters in the same
178context. Failure to do so would cause complete confusion. 178context. Failure to do so would cause complete confusion.
179 179
180@cindex symbol name hashing 180@cindex symbol name
181@cindex hashing
182@cindex obarray 181@cindex obarray
183@cindex bucket (in obarray)
184 When the Lisp reader encounters a name that references a symbol in 182 When the Lisp reader encounters a name that references a symbol in
185the source code, it reads all the characters of that name. Then it 183the source code, it reads all the characters of that name. Then it
186looks up that name in a table called an @dfn{obarray} to find the 184looks up that name in a table called an @dfn{obarray} to find the
187symbol that the programmer meant. The technique used in this lookup 185symbol that the programmer meant. An obarray is an unordered container
188is called ``hashing'', an efficient method of looking something up by 186of symbols.
189converting a sequence of characters to a number, known as a ``hash
190code''. For example, instead of searching a telephone book cover to
191cover when looking up Jan Jones, you start with the J's and go from
192there. That is a simple version of hashing. Each element of the
193obarray is a @dfn{bucket} which holds all the symbols with a given
194hash code; to look for a given name, it is sufficient to look through
195all the symbols in the bucket for that name's hash code. (The same
196idea is used for general Emacs hash tables, but they are a different
197data type; see @ref{Hash Tables}.)
198 187
199When looking up names, the Lisp reader also considers ``shorthands''. 188When looking up names, the Lisp reader also considers ``shorthands''.
200If the programmer supplied them, this allows the reader to find a 189If the programmer supplied them, this allows the reader to find a
201symbol even if its name isn't present in its full form in the source 190symbol even if its name isn't present in its full form in the source
202code. Of course, the reader needs to be aware of some pre-established 191code. @xref{Shorthands}.
203context about such shorthands, much as one needs context to be to able
204to refer uniquely to Jan Jones by just the name ``Jan'': it's probably
205fine when amongst the Joneses, or when Jan has been mentioned
206recently, but very ambiguous in any other situation.
207@xref{Shorthands}.
208 192
209@cindex interning 193@cindex interning
210 If a symbol with the desired name is found, the reader uses that 194 If a symbol with the desired name is found, the reader uses that
@@ -236,23 +220,6 @@ to gain access to it is by finding it in some other object or as the
236value of a variable. Uninterned symbols are sometimes useful in 220value of a variable. Uninterned symbols are sometimes useful in
237generating Lisp code, see below. 221generating Lisp code, see below.
238 222
239 In Emacs Lisp, an obarray is actually a vector. Each element of the
240vector is a bucket; its value is either an interned symbol whose name
241hashes to that bucket, or 0 if the bucket is empty. Each interned
242symbol has an internal link (invisible to the user) to the next symbol
243in the bucket. Because these links are invisible, there is no way to
244find all the symbols in an obarray except using @code{mapatoms} (below).
245The order of symbols in a bucket is not significant.
246
247 In an empty obarray, every element is 0, so you can create an obarray
248with @code{(make-vector @var{length} 0)}. @strong{This is the only
249valid way to create an obarray.} Prime numbers as lengths tend
250to result in good hashing; lengths one less than a power of two are also
251good.
252
253 @strong{Do not try to put symbols in an obarray yourself.} This does
254not work---only @code{intern} can enter a symbol in an obarray properly.
255
256@cindex CL note---symbol in obarrays 223@cindex CL note---symbol in obarrays
257@quotation 224@quotation
258@b{Common Lisp note:} Unlike Common Lisp, Emacs Lisp does not provide 225@b{Common Lisp note:} Unlike Common Lisp, Emacs Lisp does not provide
@@ -262,9 +229,21 @@ Emacs Lisp provides a different namespacing system called
262``shorthands'' (@pxref{Shorthands}). 229``shorthands'' (@pxref{Shorthands}).
263@end quotation 230@end quotation
264 231
232@defun obarray-make &optional size
233This function creates and returns an empty obarray object.
234The optional @var{size} may be used to specify the number of symbols
235that it is expected to hold, but since obarrays grow automatically
236as needed, this rarely provide any benefit.
237@end defun
238
239@defun obarrayp object
240This function returns @code{t} if @var{object} is an obarray,
241@code{nil} otherwise.
242@end defun
243
265 Most of the functions below take a name and sometimes an obarray as 244 Most of the functions below take a name and sometimes an obarray as
266arguments. A @code{wrong-type-argument} error is signaled if the name 245arguments. A @code{wrong-type-argument} error is signaled if the name
267is not a string, or if the obarray is not a vector. 246is not a string, or if the obarray is not an obarray object.
268 247
269@defun symbol-name symbol 248@defun symbol-name symbol
270This function returns the string that is @var{symbol}'s name. For example: 249This function returns the string that is @var{symbol}'s name. For example:
@@ -416,6 +395,10 @@ If @code{unintern} does delete a symbol, it returns @code{t}. Otherwise
416it returns @code{nil}. 395it returns @code{nil}.
417@end defun 396@end defun
418 397
398@defun obarray-clear obarray
399This function removes all symbols from @var{obarray}.
400@end defun
401
419@node Symbol Properties 402@node Symbol Properties
420@section Symbol Properties 403@section Symbol Properties
421@cindex symbol property 404@cindex symbol property