Is there a way using format to repeat a word

common-lisp, format

Solution

Yes. `~{` will normally repeat as long as there are arguments left to be processed, but adding a prefix argument will limit the number of iterations. Making the prefix argument `v` will fetch it from the argument list. Adding `@` will make the iteration use the rest of the arguments as input.

Since the part between the braces never use up any arguments, the prefix will determine the number of iterations. However, there must be at least one argument (I arbitrarily chose `nil`), or else the iteration will terminate immediately.

(format t "~v@{-~}" repeat-times nil)

Problem

I want something like this in common lisp. ``` (format t "~{-~}" repeat-times) ``` if repeat-times is 5 will print ----- if repeat-times is 10 will print ---------- Is the format exist a way to do that?

Original source

Related problems