Next: , Previous: , Up: Symbols   [Contents][Index]

5.6.3 Obarrays

An obarray is the structure used to ensure that no two symbols have the same name and to provide quick access to a symbol given its name. An obarray is a vector, each element of the vector is a chain of symbols whose names share the same hash-code (a bucket). These symbols are chained together through links which are invisible to Lisp programs: if you examine an obarray you will see that each bucket looks as though it has at most one symbol stored in it.

The normal way to reference a symbol is simply to type its name in the program, when the Lisp reader encounters a name of a symbol it looks in the default obarray for a symbol of that name. If the named symbol doesn’t exist it is created and hashed into the obarray—this process is known as interning the symbol, for more details see Interning.

Variable: obarray

This variable contains the obarray that the read function uses when interning symbols.

Function: make-obarray size

This function creates a new obarray with size hash buckets (this should probably be a prime number for the fewest hash collisions).

This is the only way of creating an obarray. make-vector is not suitable.

Function: find-symbol symbol-name #!optional obarray

This function scans the specified obarray (obarray or the value of the variable obarray if obarray is undefined) for a symbol whose name is the string symbol-name. The value returned is the symbol if it can be found or false otherwise.

(find-symbol "setq")
    ⇒ setq
Function: apropos regexp #!optional predicate obarray

Returns a list of symbols from the obarray obarray (or the default) whose print name matches the regular expression regexp (see Regular Expressions). If predicate is true, each symbol which matches regexp is applied to the function predicate, if the value is true it is considered a match.

The predicate argument is useful for restricting matches to a certain type of symbol, for example only commands.

(apropos "^yank" 'commandp)
    ⇒ (yank-rectangle yank yank-to-mouse)

Next: , Previous: , Up: Symbols   [Contents][Index]