Re: FORMAT ~<...~:@> PUZZLE
- From: Peter Seibel <peter@xxxxxxxxxxxxxxx>
- Date: Tue, 29 Nov 2005 16:37:06 GMT
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/
.
- Follow-Ups:
- Re: FORMAT ~<...~:@> PUZZLE
- From: Vladimir Zolotykh
- Re: FORMAT ~<...~:@> PUZZLE
- References:
- FORMAT ~<...~:@> PUZZLE
- From: Vladimir Zolotykh
- FORMAT ~<...~:@> PUZZLE
- Prev by Date: Reddit Guys on the Pros and Cons of Lisp
- Next by Date: Re: Hints on recursion
- Previous by thread: FORMAT ~<...~:@> PUZZLE
- Next by thread: Re: FORMAT ~<...~:@> PUZZLE
- Index(es):
Relevant Pages
|