Re: FORMAT ~<...~:@> PUZZLE



Vladimir Zolotykh <gsmith@xxxxxxxxxxxxx> writes:

> The following simple function
> (defun foo (n)
> (let* ((*print-right-margin* n)
> (a '("Whan" "you're" "lost" "in" "the" "Wild,"
> "and" "you're" "scared" "as" "a" "child,"
> "And" "Death" "looks" "you" "bang"
> "in" "the" "eye,")))
> (format t "~@<~{~A~^ ~}~:@>" a)))
> if called (cl-user::foo 10)
> prints one word at a line. So does (cl-user::foo 20),30,40.
> And only (cl-user::foo 50) prints
>
> Whan you're lost in the Wild, and you're scared
> as a child, And Death looks you bang in the eye,
>
> What's wrong? I'd expect that calls with n less that 50 (e.g 20, 30, 40)
> would also print _formatted_ paragraph. Where was I wrong?

I'm sure I don't actually understand this but poking around a bit I
came up with this:

(defun foo (n)
(let ((*print-right-margin* n)
(*print-miser-width* nil)
(a '("Whan" "you're" "lost" "in" "the" "Wild,"
"and" "you're" "scared" "as" "a" "child,"
"And" "Death" "looks" "you" "bang"
"in" "the" "eye,")))
(format t "~@<~;~{~A~^ ~}~;~:@>" a)))

-Peter

--
Peter Seibel * peter@xxxxxxxxxxxxxxx
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp * http://www.gigamonkeys.com/book/
.



Relevant Pages