[alexandria-devel] Question about FORMAT-SYMBOL

Faré fahree at gmail.com
Mon Jul 30 15:09:21 UTC 2012


On Sat, Jul 28, 2012 at 5:03 PM, Orivej Desh <orivej at gmx.fr> wrote:
> On 20 June 2011 22:28, Luís Oliveira <luismbo at gmail.com> wrote:
>
>> We just came across an issue on #quicklisp where a user had set his
>> *PRINT-CASE* to :DOWNCASE and that caused FORMAT-SYMBOL to intern
>> lower-case symbols, thus breaking the idiom I described.
>>
>> Should fix my code to use SYMBOLICATE instead or should FORMAT-SYMBOL
>> use WITH-STANDARD-IO-SYNTAX?
>>
>> Any opinions?
>
>
> Nikodemus Siivola <nikodemus at random-state.net> replied:
>
>
>> Using W-S-IO-S in FORMAT-SYMBOL sounds reasonable to me.
>
>
> This has not been done, and is still needed.  In particular, osicat-sys
> has (alexandria:format-symbol t "~A-~A" name '#:designator).
>
Speaking of symbolicate and format symbol,
could we have something like the code below?

Also can alexandria depend on asdf?
If so, can we just reexport some ASDF utilities?
Or else, can alexandria duplicate them?
appendf, orf, strcat come to mind.
Maybe also probe-file*, find-symbol*, while-collecting.
Might already exist under different names:
length=n-p, first-char, last-char, remove-keys, remove-keywords.
Things that are incompatible: ends-with

Also, no one replied to my previous nest proposals:

(defmacro nest (&rest things)
  (reduce #'(lambda (outer inner) (append outer (list inner)))
          things :from-end t))
(defmacro tsen (&rest things)
  (reduce #'(lambda (inner outer) (append outer (list inner)))
          things :from-end nil))



(in-package :alexandria)

(defun convert-to-string (x)
  "transform some stuff into a string"
  (typecase x
    (string x)
    (null "")
    (character (string x))
    (symbol (symbol-name x))
    (t (with-standard-io-syntax (princ-to-string x)))))

(defun reduce/strcat (string-list &key (element-type 'character) new)
  "concatenate the contents"
  (cond
    ((null string-list) "")
    ((and (null (cdr string-list)) (not new)) (first string-list))
    (t
     (loop :with length = (reduce #'+ string-list :key #'length)
       :with result = (make-string length :element-type element-type)
       :for index = 0 :then (+ index (length string))
       :for string :in string-list
       :do (replace result string :start1 index)
       :finally (return result)))))

(defun stringicate (&rest rest)
  "make a string by concatenating stuff"
  (reduce/strcat (mapcar #'convert-to-string rest)))

(defun symbolicate-in (package &rest rest)
  (maybe-intern (apply 'stringicate rest) package))

(defun symbolicate (&rest rest)
  (apply 'symbolicate-in *package* rest))

(defun keywordicate (&rest rest)
  (apply 'symbolicate-in :keyword rest))

(defun gensymicate (&rest rest)
  (gensym (apply 'stringicate rest)))

—♯ƒ • François-René ÐVB Rideau •Reflection&Cybernethics• http://fare.tunes.org
Any sufficiently advanced bug is indistinguishable from a feature.
		— Rich Kulawiec




More information about the alexandria-devel mailing list