Skip to main content

make-symbol

make-symbol Function

Syntax:

make-symbol name → new-symbol

Arguments and Values:

name—a string.

new-symbol—a fresh, uninterned symbol.

Description:

make-symbol creates and returns a fresh, uninterned symbol whose name is the given name. The new-symbol is neither bound nor fbound and has a null property list.

It is implementation-dependent whether the string that becomes the new-symbol’s name is the given name or a copy of it. Once a string has been given as the name argument to make-symbol, the consequences are undefined if a subsequent attempt is made to alter that string.

Examples:

(setq temp-string "temp")"temp" 
(setq temp-symbol (make-symbol temp-string)) → #:|temp|
(symbol-name temp-symbol)"temp"
(eq (symbol-name temp-symbol) temp-string) → implementation-dependent
(find-symbol "temp") → NIL, NIL
(eq (make-symbol temp-string) (make-symbol temp-string)) → false

Exceptional Situations:

Should signal an error of type type-error if name is not a string.

See Also:

copy-symbol

Notes:

No attempt is made by make-symbol to convert the case of the name to uppercase. The only case conversion which ever occurs for symbols is done by the Lisp reader . The program interface to symbol creation retains case, and the program interface to interning symbols is case-sensitive.

copy-symbol

Expanded Reference: make-symbol

Basic usage

make-symbol creates a fresh, uninterned symbol with the given string as its name. No case conversion is performed.

(make-symbol "HELLO")
;; => #:HELLO
(make-symbol "hello")
;; => #:|hello| (lowercase name preserved)

The new symbol is uninterned

The returned symbol has no home package and is not interned anywhere.

(let ((sym (make-symbol "TEMP")))
(values (symbol-name sym)
(symbol-package sym)))
=> "TEMP"
=> NIL

Each call creates a distinct symbol

Even with the same name, each call to make-symbol produces a new, unique symbol.

(let ((a (make-symbol "X"))
(b (make-symbol "X")))
(values (eq a b)
(string= (symbol-name a) (symbol-name b))))
=> NIL
=> T

The new symbol is unbound and unfbound

A freshly created symbol has no value, no function definition, and an empty property list.

(let ((sym (make-symbol "FRESH")))
(values (boundp sym)
(fboundp sym)
(symbol-plist sym)))
=> NIL
=> NIL
=> NIL

Using make-symbol for private data keys

Uninterned symbols are useful as keys that cannot collide with any interned symbol.

(let ((secret-key (make-symbol "SECRET"))
(obj (make-symbol "OBJ")))
(setf (get obj secret-key) "hidden-value")
(values (get obj secret-key)
(get obj 'secret)))
=> "hidden-value"
=> NIL

No case conversion

Unlike the Lisp reader, make-symbol does not upcase the name string. The name is used exactly as given.

(symbol-name (make-symbol "mixedCase"))
=> "mixedCase"
(symbol-name (make-symbol "ALL-CAPS"))
=> "ALL-CAPS"