From: Barry Margolin
Subject: Re: easy plural formatting question
Date: 
Message-ID: <XRtR7.20$tk5.51743@burlma1-snr2>
In article <···············@osf1.gmu.edu>,
Myriam Abramson  <········@osf1.gmu.edu> wrote:
>How do I form the plural of "inch" to "inches"? I tried
>(format t "inch~P" 2 )
>inchs
>(format t ······@P" 2 )
>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))

-- 
Barry Margolin, ······@genuity.net
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.

From: Kent M Pitman
Subject: Re: easy plural formatting question
Date: 
Message-ID: <sfw667d338n.fsf@shell01.TheWorld.com>
Barry Margolin <······@genuity.net> writes:

> In article <···············@osf1.gmu.edu>,
> Myriam Abramson  <········@osf1.gmu.edu> wrote:
> >How do I form the plural of "inch" to "inches"? I tried
> >(format t "inch~P" 2 )
> >inchs
> >(format t ······@P" 2 )
> >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 ...
From: Marco Antoniotti
Subject: Re: easy plural formatting question
Date: 
Message-ID: <y6cbsh51ncu.fsf@octagon.mrl.nyu.edu>
Kent M Pitman <······@world.std.com> writes:

> Barry Margolin <······@genuity.net> writes:
> 
> > In article <···············@osf1.gmu.edu>,
> > Myriam Abramson  <········@osf1.gmu.edu> wrote:
> > >How do I form the plural of "inch" to "inches"? I tried
> > >(format t "inch~P" 2 )
> > >inchs
> > >(format t ······@P" 2 )
> > >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'.
From: Kalle Olavi Niemitalo
Subject: Re: easy plural formatting question
Date: 
Message-ID: <874rmwg8w0.fsf@Astalo.y2000.kon.iki.fi>
Kent M Pitman <······@world.std.com> writes:

> 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?
From: Kent M Pitman
Subject: Re: easy plural formatting question
Date: 
Message-ID: <sfwg06ghios.fsf@shell01.TheWorld.com>
Kalle Olavi Niemitalo <···@iki.fi> writes:

> Kent M Pitman <······@world.std.com> writes:
> 
> > 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". :)

> 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.

> 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.
From: Christopher Stacy
Subject: Re: easy plural formatting question
Date: 
Message-ID: <un10p303q.fsf@spacy.Boston.MA.US>
>>>>> On Tue, 11 Dec 2001 20:17:59 GMT, Barry Margolin ("Barry") writes:
 Barry> In article <···············@osf1.gmu.edu>,
 Barry> Myriam Abramson  <········@osf1.gmu.edu> wrote:
 >> How do I form the plural of "inch" to "inches"? I tried
 >> (format t "inch~P" 2 )
 >> inchs
 >> (format t ······@P" 2 )
 >> 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"
From: Christopher Stacy
Subject: Re: easy plural formatting question
Date: 
Message-ID: <uk7vt2zv3.fsf@spacy.Boston.MA.US>
>>>>> On Tue, 11 Dec 2001 20:17:59 GMT, Barry Margolin ("Barry") writes:
 Barry> In article <···············@osf1.gmu.edu>,
 Barry> Myriam Abramson  <········@osf1.gmu.edu> wrote:
 >> How do I form the plural of "inch" to "inches"? I tried
 >> (format t "inch~P" 2 )
 >> inchs
 >> (format t ······@P" 2 )
 >> 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"
From: Christopher Stacy
Subject: Re: easy plural formatting question
Date: 
Message-ID: <uheqx2zcv.fsf@spacy.Boston.MA.US>
>>>>> On Tue, 11 Dec 2001 20:17:59 GMT, Barry Margolin ("Barry") writes:
 Barry> In article <···············@osf1.gmu.edu>,
 Barry> Myriam Abramson  <········@osf1.gmu.edu> wrote:
 >> How do I form the plural of "inch" to "inches"? I tried
 >> (format t "inch~P" 2 )
 >> inchs
 >> (format t ······@P" 2 )
 >> 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"