Shammer's Philosophy

My private adversaria

Lisp repeat-string

I wrote this article to concatenate some character without dotimes, using with-output-to-string instead. But, I noticed more easy way to recursive function. Here is a last version.

(defun str (x)
  (typecase x
    (cons (concatenate 'string (str (car x)) (str (cdr x))))
    (string x)
    (number (write-to-string x))
    (character (string x))
    (t "")))

(defun reps (c s)
  (declare (integer c) (atom s))
  (if (eql c 1)
      (str s)
      (concat (str s) (reps (- c 1) s))))