How to add same character repeatedly without dotimes?
Sometimes I want to add some character repeatedly like generating something depended on how many there are. For example, organizing a file name with sequence numbers which might be different length, the length of sequence number 0 is 1, but the length of sequence number 1000 is 4, I want to organize like SEQ-0000 and SEQ-1000.
I use dotimes to fix this distance of sequence number character's length like below.
? (defparameter x "X") X ? x "X" ? (dotimes (n 5) (setf x (concat x "0"))) NIL ? x "X00000" ?
This can do what I want to do but this is come true by side effect, so it is not beautiful. I looked for the way and the following might be best.
? (loop for i from 0 to 2 collect "0") ("0" "0" "0") ? (list "file-" (loop for i from 0 to 2 collect "0")) ("file-" ("0" "0" "0")) ? (flatten (list "file-" (loop for i from 0 to 2 collect "0") "345")) ("file-" "0" "0" "0" "345") ? (with-output-to-string (s) (dolist (e (flatten (list "file-" (loop for i from 0 to 2 collect "0") "1"))) (princ e s))) "file-0001" ?
In this example, hard-coded how many 0 should be added. But, editing this value to be determined dynamically, this function would be better.