Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

easy plural formatting question

5 views
Skip to first unread message

Barry Margolin

unread,
Dec 11, 2001, 3:17:59 PM12/11/01
to
In article <mtssnah...@osf1.gmu.edu>,
Myriam Abramson <mabr...@osf1.gmu.edu> wrote:
>How do I form the plural of "inch" to "inches"? I tried
>(format t "inch~P" 2 )
>inchs
>(format t "inch~@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, bar...@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.

Geoff Summerhayes

unread,
Dec 11, 2001, 3:20:59 PM12/11/01
to

"Myriam Abramson" <mabr...@osf1.gmu.edu> wrote in message
news:mtssnah...@osf1.gmu.edu...
>
> Hi!

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

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

---------
Geoff

Erik Naggum

unread,
Dec 11, 2001, 3:25:41 PM12/11/01
to
* Myriam Abramson <mabr...@osf1.gmu.edu>

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

Kent M Pitman

unread,
Dec 11, 2001, 3:34:32 PM12/11/01
to
Barry Margolin <bar...@genuity.net> writes:

> In article <mtssnah...@osf1.gmu.edu>,
> Myriam Abramson <mabr...@osf1.gmu.edu> wrote:
> >How do I form the plural of "inch" to "inches"? I tried
> >(format t "inch~P" 2 )
> >inchs
> >(format t "inch~@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 ...

Kalle Olavi Niemitalo

unread,
Dec 11, 2001, 3:35:24 PM12/11/01
to
Myriam Abramson <mabr...@osf1.gmu.edu> writes:

> 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 "~/".

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

Marco Antoniotti

unread,
Dec 11, 2001, 4:02:57 PM12/11/01
to

Kent M Pitman <pit...@world.std.com> writes:

> Barry Margolin <bar...@genuity.net> writes:
>
> > In article <mtssnah...@osf1.gmu.edu>,
> > Myriam Abramson <mabr...@osf1.gmu.edu> wrote:
> > >How do I form the plural of "inch" to "inches"? I tried
> > >(format t "inch~P" 2 )
> > >inchs
> > >(format t "inch~@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'.

Christopher Stacy

unread,
Dec 11, 2001, 4:42:17 PM12/11/01
to
>>>>> On Tue, 11 Dec 2001 20:17:59 GMT, Barry Margolin ("Barry") writes:
Barry> In article <mtssnah...@osf1.gmu.edu>,

Barry> Myriam Abramson <mabr...@osf1.gmu.edu> wrote:
>> How do I form the plural of "inch" to "inches"? I tried
>> (format t "inch~P" 2 )
>> inchs
>> (format t "inch~@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"

Christopher Stacy

unread,
Dec 11, 2001, 4:47:28 PM12/11/01
to
>>>>> On Tue, 11 Dec 2001 20:17:59 GMT, Barry Margolin ("Barry") writes:
Barry> In article <mtssnah...@osf1.gmu.edu>,
Barry> Myriam Abramson <mabr...@osf1.gmu.edu> wrote:
>> How do I form the plural of "inch" to "inches"? I tried
>> (format t "inch~P" 2 )
>> inchs
>> (format t "inch~@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~]"

Christopher Stacy

unread,
Dec 11, 2001, 4:58:24 PM12/11/01
to
>>>>> On Tue, 11 Dec 2001 20:17:59 GMT, Barry Margolin ("Barry") writes:
Barry> In article <mtssnah...@osf1.gmu.edu>,
Barry> Myriam Abramson <mabr...@osf1.gmu.edu> wrote:
>> How do I form the plural of "inch" to "inches"? I tried
>> (format t "inch~P" 2 )
>> inchs
>> (format t "inch~@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~]"

Kalle Olavi Niemitalo

unread,
Dec 12, 2001, 3:06:23 AM12/12/01
to
Kent M Pitman <pit...@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?

Kent M Pitman

unread,
Dec 12, 2001, 4:49:23 AM12/12/01
to
Kalle Olavi Niemitalo <k...@iki.fi> writes:

> Kent M Pitman <pit...@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.

0 new messages