[alexandria-devel] concatenate-symbol

Attila Lendvai attila.lendvai at gmail.com
Thu Nov 16 15:44:59 UTC 2006


i've got this ready to be pushed and i suggest this for inclusion
and/or discussion:

(defun concatenate-symbol (&rest args)
  "A DWIM symbol concatenate: Args will be converted to string and be
concatenated
to form the resulting symbol with one exception: when a package is
encountered then
it is stored as the target package to use at intern. If there was no package
among the args then the symbol-package of the first symbol encountered will be
used. If there are neither packages nor symbols among the args then
the result will
be interned into the current package at the time of calling."
  (let* ((package nil)
         (symbol-name (string-upcase
                       (with-output-to-string (str)
                         (dolist (arg args)
                           (typecase arg
                             (string (write-string arg str))
                             (package (setf package arg))
                             (symbol (unless package
                                       (setf package (symbol-package arg)))
                                     (write-string (symbol-name arg) str))
                             (integer (write-string (princ-to-string arg) str))
                             (character (write-char arg) str)
                             (t (error "Cannot convert argument ~S to
symbol" arg))))))))
    (if package
        (intern symbol-name package)
        (intern symbol-name))))

-- 
- attila

"- The truth is that I've been too considerate, and so became
unintentionally cruel...
 - I understand.
 - No, you don't understand! We don't speak the same language!"
(Ingmar Bergman - Smultronstället)


More information about the alexandria-devel mailing list