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

5.6.5 Interning

Interning a symbol means to store it in an obarray so that it can be found in the future: all variables and named-functions are found through interned symbols.

When a symbol is interned a hash function is applied to its print name to determine which bucket in the obarray it should be stored in. Then it is simply pushed onto the front of that bucket’s chain of symbols.

Normally all interning is done automatically by the Lisp reader. When it encounters the name of a symbol which it can’t find in the default obarray (the value of the variable obarray) it creates a new symbol of that name and interns it. This means that no two symbols can have the same print name, and that the read syntax of a particular symbol always produces the same object (unless the value of obarray is altered).

(eq 'some-symbol 'some-symbol)
    ⇒ t
Function: intern symbol-name #!optional obarray

This function uses find-symbol to search the obarray (or the standard obarray) for a symbol called symbol-name. If a symbol of that name is found it is returned, otherwise a new symbol of that name is created, interned into the obarray, and returned.

(intern "setq")
    ⇒ setq

(intern "my-symbol" my-obarray)
    ⇒ my-symbol
Function: intern-symbol symbol #!optional obarray

Interns the symbol symbol into the obarray obarray (or the standard one) then returns the symbol. If symbol is currently interned in an obarray an error is signalled.

(intern-symbol (make-symbol "foo"))
    ⇒ foo

(intern-symbol 'foo)
    error→ Error: Symbol is already interned, foo
Function: unintern symbol #!optional obarray

This function removes the symbol symbol from the obarray obarray then returns the symbol.

Beware! this function should be used with extreme caution—once you unintern a symbol there may be no way to recover it.

(unintern 'setq)                ;This is extremely stupid
    ⇒ setq

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