Re: cl-quiz



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
.



Relevant Pages

  • Re: Is there a way to define print offsets?
    ... Be aware too that printing the exact same file on another printer - even of the same make and model - is likely to result in minor differences in the physical margins. ... basis of content, and the format reviewer, who makes his decision based ... >drivers that are probably different to those that the reviewers are using). ...
    (microsoft.public.word.docmanagement)
  • Re: Rounding error
    ... this is just to be able to use the same format for input and output. ... blank (single space before printing) ... page carriage control codes 1-9 should skip to. ... I believe that one was used for the prank described. ...
    (comp.lang.fortran)
  • Re: bckgrnd color doesnt print (is ticked in print options)
    ... Format | Background is intended for Web pages. ... background using the "Print background colors and images" check box on the ... printing the background. ... document is to add a "watermark." ...
    (microsoft.public.word.docmanagement)
  • Re: Where have you gone, Bob Monaghan ???
    ... in nearly all regards, and is starting to make serious inroads on MF as well. ... It needs to be considered that his method of printing limits resolution and results more than his chosen format. ... anyone using film to get the ultimate in quality will be using large format instead. ...
    (rec.photo.equipment.35mm)
  • Re: Styles that display but dont print
    ... If you want the space occupied by the nonprinting text to collapse during ... printing, then Hidden is the only attribute you can use. ... Jeff wrote: ... you can format it as hidden and set your view options to show ...
    (microsoft.public.word.docmanagement)