Subject: Re: With format, how to print a variable number of spaces
From: rpw3@rpw3.org (Rob Warnock)
Date: Tue, 06 Jun 2006 21:04:35 -0500
Newsgroups: comp.lang.lisp
Message-ID: <OradndIUWOquqRvZnZ2dnUVZ_q6dnZ2d@speakeasy.net>
Pascal Bourguignon  <pjb@informatimago.com> wrote:
+---------------
| Kent M Pitman <pitman@nhplace.com> writes:
| > So if you do:
| >   (defun spaces (n) (format nil "~V{ ~}" n '(IGNORED)))
| > you'll get what you want if you want to use FORMAT.
| > ...  not that I'd advocate FORMAT.  ...
| 
| It seems to me that:
|     (format t "~V,,,VA" width fill "")
| is more readable and better: it gives format an opportunity to do it
| more efficiently.
+---------------

Indeed. But Kent's method raises another interesting possibility,
for when the thing you want to repeat multiple times isn't a
single character:

    > (loop for i below 4 do
        (format t "I'm so~V{ ~A~:*~} happy!~%" i '("very")))
    I'm so happy!
    I'm so very happy!
    I'm so very very happy!
    I'm so very very very happy!
    NIL
    > 


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607