Re: cl-quiz
- From: David Sletten <david@xxxxxxxxxxxxx>
- Date: Sun, 30 Apr 2006 02:34:34 GMT
Tel A. wrote:
A question in pertinance to the quiz:
How could one write a format directive something to the effect of
;wrong
(format nil "~r ~a~:p" 10 "apricot")
=> "10 apricots"
(format nil "~r ~a~:p" 1 "apricot")
=> "1 apricot"
I would like it to take two arguments, print the first one as a real
then print the second one, a string, with correct pluralization as per
the first argument.
Anyone done this before?
There's so much magic in FORMAT that it takes a while to get familiar with it all:
http://www.lispworks.com/documentation/HyperSpec/Body/22_cga.htm
You can use ~n:* to back up n arguments, with 1 the default:
(format nil "~r ~a~:*~:p" 10 "apricot") => "ten apricots"
But based on your description you probably want ~D rather than ~R:
(format nil "~d ~a~:*~:p" 1 "apricot") => "1 apricot"
Unless you actually meant "float" when you wrote "real":
(format nil "~f ~a~:*~:p" 1 "apricot") => "1.0 apricot"
(Remember that you're not really "printing" anything when you use NIL as the first argument to FORMAT.)
Aloha,
David Sletten
.
- References:
- [ANN] cl-quiz
- From: Marco Baringer
- Re: cl-quiz
- From: Tel A.
- [ANN] cl-quiz
- Prev by Date: Re: cl-quiz
- Next by Date: Re: Crazy macro
- Previous by thread: Re: cl-quiz
- Next by thread: Crazy macro
- Index(es):
Relevant Pages
|
|