[alexandria-devel] concatenate-symbol

Nikodemus Siivola nikodemus at random-state.net
Mon Nov 20 16:52:48 UTC 2006


Nikodemus Siivola <nikodemus at random-state.net> writes:

> "Attila Lendvai" <attila.lendvai at gmail.com> writes:
>
>> 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."

Here's my take:

(defun concatenate-symbol (package &rest arguments)
  "Returns a symbol whose name is a concatenation of printed representations
of ARGUMENTS, printed as if by PRINC. If PACKAGE is NIL, the symbol is a fresh
uninterned symbol. If PACKAGE is T, the symbol is interned in the current
package. Otherwise the symbol is interned in the package designated by
PACKAGE."
  (let ((name (with-output-to-string (s)
                (dolist (part arguments)
                  (princ part s)))))
    (if package
        (intern name (if (eq t package) *package* package))
        (make-symbol name))))

I'm a still bit non-plussed of when

  (concatenate-symbol pkg "FOO-" (incf *my-counter* i) "-DING-" i "-" tail)

would be preferable to

  (format-symbol pkg "FOO-~D-DING-~D-~A" (incf *my-counter* i) i tail)

...so I assume I am misunderstanding the typical use-cases.

Cheers,

  -- Nikodemus              Schemer: "Buddha is small, clean, and serious."
                   Lispnik: "Buddha is big, has hairy armpits, and laughs."



More information about the alexandria-devel mailing list