Skip to main content
edited tags
Link
Rainer Joswig
  • 140k
  • 11
  • 230
  • 357
Source Link

LISP - Make new unique symbol

In a Common Lisp program, I want to find a way to generate a new symbol that is not in use in the program at the time. I am aware of the (gensym) function, but this makes symbols that may already be present in the program. I have some understanding that I need to intern the symbol, so I tried this:

(defun new-symbol () (intern (symbol-name (gensym)))) 

Which seems to get halfway to the answer. For instance,

[1]> (new-symbol) G3069 NIL [2]> (new-symbol) G3070 NIL [3]> (defvar a 'G3071) A [4]> (new-symbol) G3071 :INTERNAL 

As you can see, the function seems to recognize that the symbol 'G3071' is already in use elsewhere, but I don't know how to get it to generate a new symbol if that is the case.