I am aware of the (gensym) function, but this makes symbols that may already be present in the program.I am aware of the (gensym) function, but this makes symbols that may already be present in the program.
Function MAKE-SYMBOL
Syntax:
make-symbol name ⇒ new-symbol
Arguments and Values:
name—a string.
new-symbol—a fresh, uninterned symbol.
Regarding your second point:
I have some understanding that I need to intern the symbol, so I tried this:
No, if you want a fresh symbol, then you probably don't want to be interning anywhere. Interning is the process whereby you take a string (not a symbol) and get the symbol with the given name within a particular package. If you call intern with the same symbol name and package twice, you'll get back the same symbol, which is what you're trying to avoid.
CL-USER> (defparameter *a* (intern "A")) *A* CL-USER> (eq *a* (intern "A")) T Since gensym generates the name of the fresh symbol using *gensym-counter*, if you take the name from the gensym symbol and intern it somewhere, you could get the same symbol if someone modifies the value of *gensym-counter*. E.g.:
(let ((counter *gensym-counter*) ; save counter value (s1 (gensym))) ; create a gensym (s1) (setf *gensym-counter* counter) ; reset counter value (let ((s2 (gensym))) ; create a gensym (s2) (list s1 s2 (eq s1 s2) (symbol-name s1) (symbol-name s2) (string= (symbol-name s1) (symbol-name s2))))) ; (#:G1037 #:G1037 NIL ; different symbols ; "G1037" "G1037" T) ; same name