Lisp format a character a number of times

Solution 1:

It's nice to see so many solutions: ~A, ~<, and ~{ so far.

The ~@{ iteration construct provides a concise solution:

(format nil "~v@{~A~:*~}" 3 #\*)

Solution 2:

(format nil "~a~:*~a~:*~a~:*" #\*)
"***"

Or elaborating a bit on Joshua Taylor's answer:

(format nil "~v{~a~:*~}" 3 '(#\*))

Would be one way of doing this. Don't be confused by the asterisks in the format directive, they are control characters, not characters being printed.


In terms of efficiency, however, this:

(make-string 3 :initial-element #\*)

would be a preferred way to achieve the same effect.