Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

With format, how to print a variable number of spaces

48 views
Skip to first unread message

Robert L.

unread,
Sep 20, 2017, 4:01:12 AM9/20/17
to
Rob Warnock wrote:

> > (defparameter *digits* (apply 'concatenate 'string
> (loop for i below 10
> collect "0123456789")))
> > (loop for i below 20
> for col = (+ 20 (round (* 8 (sin (* i pi 1/4))))) do
> (format t "~&~A = ~32T~D chars~%" (subseq *digits* 0 col) col))
>
>
> 01234567890123456789 = 20 chars
> 01234567890123456789012345 = 26 chars
> 0123456789012345678901234567 = 28 chars
> 01234567890123456789012345 = 26 chars
> 01234567890123456789 = 20 chars
> 01234567890123 = 14 chars
> 012345678901 = 12 chars
> 01234567890123 = 14 chars
> 01234567890123456789 = 20 chars
> 01234567890123456789012345 = 26 chars
> 0123456789012345678901234567 = 28 chars
> 01234567890123456789012345 = 26 chars
> 01234567890123456789 = 20 chars
> 01234567890123 = 14 chars
> 012345678901 = 12 chars
> 01234567890123 = 14 chars
> 01234567890123456789 = 20 chars
> 01234567890123456789012345 = 26 chars
> 0123456789012345678901234567 = 28 chars
> 01234567890123456789012345 = 26 chars


(require srfi/42) ; do-ec
(require srfi/13) ; xsubstring

(do-ec (: i 20)
(let ((n (exact-round (+ 20 (* 8 (sin (* (/ pi 4) i)))))))
(printf "~a~a chars\n"
(~a (xsubstring "0123456789" 0 n) " =" #:width 32) n)))

01234567890123456789 = 20 chars
01234567890123456789012345 = 26 chars
0123456789012345678901234567 = 28 chars
01234567890123456789012345 = 26 chars
01234567890123456789 = 20 chars
01234567890123 = 14 chars
012345678901 = 12 chars
01234567890123 = 14 chars
01234567890123456789 = 20 chars
01234567890123456789012345 = 26 chars
0123456789012345678901234567 = 28 chars
01234567890123456789012345 = 26 chars
01234567890123456789 = 20 chars
01234567890123 = 14 chars
012345678901 = 12 chars
01234567890123 = 14 chars
01234567890123456789 = 20 chars
01234567890123456789012345 = 26 chars
0123456789012345678901234567 = 28 chars
01234567890123456789012345 = 26 chars


In Forth?

--
I don't believe in western morality, i.e. don't kill civilians or children....
The only way to fight a moral war is the Jewish way: Destroy their holy sites.
Kill men, women, and children (and cattle). --- Rabbi Manis Friedman
web.archive.org/web/20090605154706/http://www.momentmag.com/Exclusive/2009/2009-06/200906-Ask_Rabbis.html
archive.org/download/DavidDukeVideo/TheZionistMatrixOfPowerddhd.ogv

Robert L.

unread,
Sep 21, 2017, 4:27:31 PM9/21/17
to
Frank Buss wrote:

> > I have another 'format' question: say I have a list of key/value
> > pairs, in an alist:
> > '((foo 3) (bar 2) (baz 10))
> >
> > Can I use format with the list iteration operators to get output like:
> > "foo=3;bar=3;baz=10;"?
>
> I'm sure this is possible with some magic format strings, but if you want
> that non-format-gurus like me understand your code, you may write it like
> this:
>
> (loop for (key value) in '((foo 3) (bar 2) (baz 10)) do
> (format t "~a=~a;" key value))


(for-each (curry apply printf "~a=~a;") '((foo 3) (bar 2) (baz 10)))

foo=3;bar=2;baz=10;

--
Jewish drug dealers, child porn pushers, and slave traders are free
from prosecution in Israel. Israel does not consider these to be
crimes ... so long as the victims are non-Jews.
www.theoccidentalobserver.net/2009/08/the-culture-of-deceit/
0 new messages