;;AUTOLOAD: gensym
;;AUTODOC: gensym "generates a new unique symbol"
;; (gensym [radix])
;;
;; Generates new symbols in the form radix (string defaulting to "g") suffixed
;; by an increasing integer.
;;e.g.:
;;     (gensym) ==> g0
;;     (gensym) ==> g1
;;     (gensym "f") ==> f0        ; counts are independent on each radix
;;     (setq g2 "any value")
;;     (gensym) ==> g3            ; we garantee a new symbol, g2 was used

(setq gensym:table (coerce (list) Hashtable))

(defun gensym (&optional (radix "g") &aux
    (num (get gensym:table radix 0))
    symbol
  )
  (if (not (typep radix String))
    (error "Gensym radix %0 - should be string" radix)
  )
  ;; take care not to use a symbol already defined by somebody else
  (while (boundp (setq symbol (intern
	  (+ radix (coerce num String))
    )))
    (setq num (+ num 1))
  )
  (put gensym:table radix (+ num 1))
  symbol
)
  
