easy plural formatting question 
Author Message
 easy plural formatting question



Quote:
>How do I form the plural of "inch" to "inches"? I tried
>(format t "inch~P" 2 )
>inchs

>inchies
>(format t "inch~:P" 2 )
>inchs

There's no ~P option for that, so you have to roll your own.  You can do:

(format t "inch~[es~;~:;es~] 2)

(format t "inch~:[es~;~] (= 2 1))

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



Sun, 30 May 2004 04:17:59 GMT  
 easy plural formatting question


Quote:

> Hi!

> How do I form the plural of "inch" to "inches"? I tried
> (format t "inch~P" 2 )
> inchs

> inchies
> (format t "inch~:P" 2 )
> inchs

(format t "inch~[es~;~:;es~]" 2)

---------
Geoff



Sun, 30 May 2004 04:20:59 GMT  
 easy plural formatting question

| How do I form the plural of "inch" to "inches"?

(dotimes (inches 5)
  (format t "~&~D inch~:*~[es~;~:;es~]" inches))
0 inches
1 inch
2 inches
3 inches
4 inches

///
--
  The past is not more important than the future, despite what your culture
  has taught you.  Your future observations, conclusions, and beliefs are
  more important to you than those in your past ever will be.  The world is
  changing so fast the balance between the past and the future has shifted.



Sun, 30 May 2004 04:25:41 GMT  
 easy plural formatting question

Quote:



> >How do I form the plural of "inch" to "inches"? I tried
> >(format t "inch~P" 2 )
> >inchs

> >inchies
> >(format t "inch~:P" 2 )
> >inchs

> There's no ~P option for that, so you have to roll your own.  You can do:

> (format t "inch~[es~;~:;es~] 2)

> (format t "inch~:[es~;~] (= 2 1))

(ROTFL)

Following in a similar line...

(format t "inch~A" (if (= 2 1) "" "es"))

Though to be honest I don't know why just

(format t "inches") didn't occur to anyone. :)

In Symbolics Genera, btw, it works to do:

 (format t "~\\pluralize\\" 2 "inch")

None of this internationalizes well, though.  For that, might I suggest

(format t "~A" (... code involving 2 and words that mean "inch" ...))
 => ... stuff that means 2 inches ...



Sun, 30 May 2004 04:34:32 GMT  
 easy plural formatting question

Quote:

> How do I form the plural of "inch" to "inches"?

"~P" does not support that, but you can get a similar effect with "~[":

  (format t "inch~[es~;~:;es~]" 2)

i.e., format "es" if the argument is 0, nothing if it is 1, or
"es" otherwise.

However, this cannot handle floating-point numbers.  If you need
to support them too, it may be easiest to insert (eql 2 1) as a
separate argument.  If you can't change the list of arguments,
you could put the comparison in a function and call that with "~/".

Quote:
> (format t "inch~:P" 2 )

Don't do that.  With the colon modifier, tilde-P backs to the
previous argument, but here you have no previous argument.


Sun, 30 May 2004 04:35:24 GMT  
 easy plural formatting question


Quote:



> > >How do I form the plural of "inch" to "inches"? I tried
> > >(format t "inch~P" 2 )
> > >inchs

> > >inchies
> > >(format t "inch~:P" 2 )
> > >inchs

> > There's no ~P option for that, so you have to roll your own.  You can do:

> > (format t "inch~[es~;~:;es~] 2)

> > (format t "inch~:[es~;~] (= 2 1))

> (ROTFL)

> Following in a similar line...

> (format t "inch~A" (if (= 2 1) "" "es"))

> Though to be honest I don't know why just

> (format t "inches") didn't occur to anyone. :)

Because in this country you insist on the Imperial System instead
of the MKS one. :)

        (format t "meter~P" 2)

Cheers

--
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
                    "Hello New York! We'll do what we can!"
                           Bill Murray in `Ghostbusters'.



Sun, 30 May 2004 05:02:57 GMT  
 easy plural formatting question
Quote:
>>>>> On Tue, 11 Dec 2001 20:17:59 GMT, Barry Margolin ("Barry") writes:



 >> How do I form the plural of "inch" to "inches"? I tried
 >> (format t "inch~P" 2 )
 >> inchs

 >> inchies

 >> (format t "inch~:P" 2 )
 >> inchs

This one, "~:P", is supposed to be the same as plain "~P",
except that it does "~:*" (back up one argument) first.
So your example should have blown up complaining that there
was no previous argument.

 Barry> There's no ~P option for that, so you have to roll your own.
 Barry> You can do:
 Barry> (format t "inch~[es~;~:;es~] 2)
 Barry> (format t "inch~:[es~;~] (= 2 1))

If you want to use ~:P, you'll need to do something like:

(format t "~:[~D inches~;~D (metric system'~:P) centimeters~]"
        (eq *units* ':metric) 2 (* 2 2.54))

By the way, the Lisp Machine had a fancier pluralize feature that
knew a lot more about English spelling, such as:
  "turkey"  =>  "turkeys"
  "pay"     =>  "pays"
  "proxy"   =>  "proxies"
  "vax"     =>  "vaxen"
  "fireman" =>  "firemen"
  "wife"    =>  "wives"
  "grandchild" =>  "grandchildren"
  "window with a border" => "windows with borders"
  "man and a dog" => "men and dogs"



Sun, 30 May 2004 05:42:17 GMT  
 easy plural formatting question
Quote:
>>>>> On Tue, 11 Dec 2001 20:17:59 GMT, Barry Margolin ("Barry") writes:



 >> How do I form the plural of "inch" to "inches"? I tried
 >> (format t "inch~P" 2 )
 >> inchs

 >> inchies

 >> (format t "inch~:P" 2 )
 >> inchs

This one, "~:P", is supposed to be the same as plain "~P",
except that it does "~:*" (back up one argument) first.
So your example should have blown up complaining that there
was no previous argument.

 Barry> There's no ~P option for that, so you have to roll your own.
 Barry> You can do:
 Barry> (format t "inch~[es~;~:;es~] 2)
 Barry> (format t "inch~:[es~;~] (= 2 1))

If you want to use ~:P, you'll need to do something like:

(format t "~:[~D inches~;about ~D (metric system'~:P) centimeters~]"
        (eq *units* ':metric) 2 (* 2 2.54))

By the way, the Lisp Machine had a fancier pluralize feature that
knew a lot more about English spelling, such as:
  "turkey"  =>  "turkeys"
  "pay"     =>  "pays"
  "proxy"   =>  "proxies"
  "vax"     =>  "vaxen"
  "fireman" =>  "firemen"
  "wife"    =>  "wives"
  "grandchild" =>  "grandchildren"
  "window with a border" => "windows with borders"
  "man and a dog" => "men and dogs"



Sun, 30 May 2004 05:47:28 GMT  
 easy plural formatting question
Quote:
>>>>> On Tue, 11 Dec 2001 20:17:59 GMT, Barry Margolin ("Barry") writes:



 >> How do I form the plural of "inch" to "inches"? I tried
 >> (format t "inch~P" 2 )
 >> inchs

 >> inchies

 >> (format t "inch~:P" 2 )
 >> inchs

This one, "~:P", is supposed to be the same as plain "~P",
except that it does "~:*" (back up one argument) first.
So your example should have blown up complaining that there
was no previous argument.

 Barry> There's no ~P option for that, so you have to roll your own.
 Barry> You can do:
 Barry> (format t "inch~[es~;~:;es~] 2)
 Barry> (format t "inch~:[es~;~] (= 2 1))

If you want to use ~:P, you'll need to do something like:

(format t "~:[~D inches~;almost twice ~D (metric system'~:P) centimeters~]"
        (eq *units* ':metric) 2 (* 2 2.54))

By the way, the Lisp Machine had a fancier pluralize feature that
knew a lot more about English spelling, such as:
  "turkey"  =>  "turkeys"
  "pay"     =>  "pays"
  "proxy"   =>  "proxies"
  "vax"     =>  "vaxen"
  "fireman" =>  "firemen"
  "wife"    =>  "wives"
  "grandchild" =>  "grandchildren"
  "window with a border" => "windows with borders"
  "man and a dog" => "men and dogs"



Sun, 30 May 2004 05:58:24 GMT  
 easy plural formatting question

Quote:
> In Symbolics Genera, btw, it works to do:

>  (format t "~\\pluralize\\" 2 "inch")

How did Genera know how many format arguments PLURALIZE consumed?
If I do this in CL:

  (format t "~/pluralize/" 2 "inch")

then PLURALIZE gets called with arguments #<stdout> 2 NIL NIL,
and never sees "inch".  I can work around that with:

  (format t "~V/pluralize/" 2 "inch")

which uses arguments #<stdout> "inch" NIL NIL 2.

CLHS says each format argument read with V "should be an integer
or character" or NIL; can I portably expect tilde-slash will pass
other types through?



Sun, 30 May 2004 16:06:23 GMT  
 easy plural formatting question

Quote:

> > In Symbolics Genera, btw, it works to do:

> >  (format t "~\\pluralize\\" 2 "inch")

> How did Genera know how many format arguments PLURALIZE consumed?

Genera's ~\\...\\ is not, as you assume, a function call.  PLURALIZE
is not a function name that I'm just calling as a user.  Indeed, the
function name is STRING-PLURALIZE and takes only one
argument. ~\\pluralize\\ is a named format op that consumes 2 args and
decides based on the first one whether the call to STRING-PLURALIZE is
needed.  The op gets full control of parameters and args just like any
other primitive format op.  Your question is pretty much the same as
saying "how does ~? know" or "how does ~:* manage to back up?"; in both
cases, the answer is "because it's defined that way". :)

Quote:
> If I do this in CL:

>   (format t "~/pluralize/" 2 "inch")

> then PLURALIZE gets called with arguments #<stdout> 2 NIL NIL,
> and never sees "inch".

And this happens in Genera too, which is CL-compliant.  ~\\...\\ is
not defined by CL.  It's a Genera extension.

Quote:
> I can work around that with:

>   (format t "~V/pluralize/" 2 "inch")

> which uses arguments #<stdout> "inch" NIL NIL 2.

> CLHS says each format argument read with V "should be an integer
> or character" or NIL; can I portably expect tilde-slash will pass
> other types through?

I would think so, but it's a little vague.

Genera has some format op for funcall, btw.  ~Q maybe? I can't recall and
am in a different building right now than my lispm.  I vaguely remember that
~VQ could be used to pass args to a function... but that was an extension
too so I don't know if other implementations would consider it conforming.
I hope they're not wasting runtime checking for an error in this case,
though.



Sun, 30 May 2004 17:49:23 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Easy Question re spreadsheet format

2. Easy formatting questions :-)

3. HELP, EASY EASY QUESTION

4. HELP, EASY EASY QUESTION

5. simple formatting...but not so easy

6. Easiest Graphic File format to display

7. Plural of VI

8. Internationalization [was Re: Printing plural

9. Printing plural forms.

10. Internationalization [was Re: Printing plural

11. Tip of the day (handling plurals)

 

 
Powered by phpBB® Forum Software