Several times I came across the notion of uninterned symbols, but I am not entirely clear about what they are.
Is there a way to intern a symbol created with (make-symbol)?
Can I assign a value to a symbol without interning it?
Is it possible to rename a symbol (interned or uninterned)?
What else can one do with an uninterned symbol?
Update:
What is happening with symbols in this piece of code?
CL-USER> (defun func ()
(let ((var 'sym))
(print (find-symbol "sym"))
(print var)))
FUNC
CL-USER> (func)
NIL
SYM
SYM
My incorrect understanding is:
1. find-symbol prints nil, so the symbol is not intered
2. var prints sym without #: in the beginning which means it is interned
Uninterned symbols are mostly used as names or designators to avoid cluttering packages, or for related tasks.
For example:
As you can see, using
t2
in the firstdefpackage
form interns it in packaget1
, while using#:t3
in the seconddefpackage
avoids this. This is possible, becausedefpackage
takes a string designator as its first element, and a symbol doesn't need to be interned to function as a designator.These and related situations are where uninterned symbols are mostly used deliberately. You could also avoid polluting the package by using a string or a keyword, but in the first case, there may be problems with people using other than the default readtable-case, and in the second case you would pollute the keyword package, which some people care about. (There are different opinions as to whether this really is such a bad thing or not.)
Then, there are situations where a symbol loses its home-package (by
unintern
ing, for example) and becomes at least apparently uninterned. (It may still be interned in another package.)So, the answer to
is yes:
Yes, while you're losing the property that it can be uniquely identified by its name and packagage, you can still use its value slot, plist, etc.:
The consequences of modifying a symbol's name are undefined.
I really think they're mostly used as designators in package definitions, but to the general answer would be: They can be useful in situations where you want to name things without using hardcoded strings and don't want to pollute any package.
Yes
No
No
It is usually used in package declaration not to pollute the namespace of the package, in which the declaration takes place (if an ordinary symbol was used) or keyword package, because entries in
defpackage
form's:export
and:use
clauses are converted to string anyway. So, you can use it in functions, which accept anything and convert it to strings. More generally, uninterned symbols can be used as unique objects with a name and nothing else. But usually keyword symbols are used for such purpose.