Printing plural forms. 
Author Message
 Printing plural forms.

We all have seen and, in various degrees, been irritated by texts such
as:

        1 files were copied

when it should have been:

        1 file was copied

I'd like to know: when programming, how do you avoid such errors? Are
there features in the programming language you use (or other languages
you know) that make plural handling especially easy or difficult? Are
there features in your native language that make plural handling
especially difficult?

All opinions and information are welcome (though I'm more interested
in how people actually produce a correct text, rather than their
excuses for not doing so). Reply to me by email, and I'll post a
summary.

[I cross-post this to comp.lang.c, because I think I will reach a
larger audience that way.]

--
Arndt Jonasson, ZYX AB, Styrmansgatan 6, 114 54 Stockholm, Sweden



Sat, 07 Aug 1993 18:48:10 GMT  
 Printing plural forms.

Quote:

> We all have seen and, in various degrees, been irritated by texts such as:

>    1 files were copied

> when it should have been:

>    1 file was copied

> I'd like to know: when programming, how do you avoid such errors? Are
> there features in the programming language you use (or other languages
> you know) that make plural handling especially easy or difficult?

The Common Lisp function "format" has a mechanism to automatically
pluralize a word by appending an `s' when appropriate.  This is no
wonder considering that "format" even has formatting requests to
print a number with roman numerals or as english words (e.g.
"twentyfour files copied")...

In C, a common idiom (well, at least in my programs) is

   printf("%d file%s copied.\n", nfiles, "s"+(nfiles==1));

--



Sat, 07 Aug 1993 21:04:52 GMT  
 Printing plural forms.

:We all have seen and, in various degrees, been irritated by texts such
:as:

:       1 files were copied

:when it should have been:

:       1 file was copied

:I'd like to know: when programming, how do you avoid such errors? Are
:there features in the programming language you use (or other languages
:you know) that make plural handling especially easy or difficult? Are
:there features in your native language that make plural handling
:especially difficult?

:All opinions and information are welcome (though I'm more interested
:in how people actually produce a correct text, rather than their
:excuses for not doing so). Reply to me by email, and I'll post a
:summary.

The easiest solution is to avoid the problem through
rewording your messages.  For example:

        Number of files copied = 1

--
Jerry Gitomer at National Political Resources Inc, Alexandria, VA USA
I am apolitical, have no resources, and speak only for myself.
Ma Bell (703)683-9090      (UUCP:  ...{uupsi,vrdxhq}!pbs!npri6!jerry



Sun, 08 Aug 1993 00:12:15 GMT  
 Printing plural forms.
I just lifted some SML code from my Make system which does this kind
of thing. PrintCount takes a word split into stem, singular and plural.
It handles {*filter*} words like "dependencies" (what does Common Lisp come
up with: "dependencys"?)

            fun PrintCount(1, (word, single, _)) =
                   Busy.print("1 " ^ word ^ single)   |
                PrintCount(n, (word, _, plural)) =
                   Busy.print(makestring n ^ " " ^ word ^ plural)
...
            fun PrintCounts() =
               (Busy.print "Tag information: ";
                PrintCount(!DepCount, ("dependenc", "y", "ies"));
                Busy.print " found involving ";
                PrintCount(!TagCount, ("tag", "", "s"));
                Busy.print " in ";
                PrintCount(!FileCount, ("file", "", "s"));
                Busy.println ""
               )

--
Nick Rothwell,  Laboratory for Foundations of Computer Science, Edinburgh.

~~ ~~ ~~ ~~  Captain Waldorf has analogue filters. You do not.  ~~ ~~ ~~ ~~
~~ ~~ ~~ ~~ Do not try to imitate them or any of their actions. ~~ ~~ ~~ ~~



Sun, 08 Aug 1993 00:03:23 GMT  
 Printing plural forms.

Quote:

> So, one writes:

> (format t "You have ~D dependenc~*:P." n-dep)

Yucko, I think I preferred doing it my way... (he says, being otherwise
quite fond of the huge amounts of chrome adorning C's printf() lib call).

--
Nick Rothwell,  Laboratory for Foundations of Computer Science, Edinburgh.

~~ ~~ ~~ ~~  Captain Waldorf has analogue filters. You do not.  ~~ ~~ ~~ ~~
~~ ~~ ~~ ~~ Do not try to imitate them or any of their actions. ~~ ~~ ~~ ~~



Sun, 08 Aug 1993 19:40:58 GMT  
 Printing plural forms.

Quote:

>It handles {*filter*} words like "dependencies" (what does Common Lisp come
>up with: "dependencys"?)

No, it comes up with "dependencies".  The ~P construct is replaced by a
null string or "s" depending on the value of the argument; the ~*P
construct is replaced by "y" or "ies" depending on the value.  So, one
writes:

(format t "You have ~D dependenc~*:P." n-dep)

The : modifier causes it to back up the argument list.
--
Barry Margolin, Thinking Machines Corp.


{uunet,harvard}!think!barmar



Sun, 08 Aug 1993 08:12:42 GMT  
 Printing plural forms.

Quote:


>> We all have seen and, in various degrees, been irritated by texts such
>> as:
>>        1 files were copied
>> when it should have been:
>>        1 file was copied

>> I'd like to know: when programming, how do you avoid such errors?
>    printf("%d error%s copied\n", nfiles, nfiles?"s were":" was");

I think you mean
        printf("%d file%s copied\n", nfiles, (nfiles == 1)?" was":"s were");
--
======= !{sun,psuvax1,bcm,rice,decwrl,cs.utexas.edu}!shell!rjohnson =======
Feel free to correct me, but don't preface your correction with "BZZT!"
Roy Johnson, Shell Development Company


Wed, 11 Aug 1993 02:48:46 GMT  
 Printing plural forms.

:Several persons emailed to point out one or more of the the obvious errors
:in the first one.  I would correct it to
:       printf("%d file%s copied\n", nfiles, nfiles=1?" was":"s were");
       printf("%d file%s copied\n", nfiles, nfiles==1?" was":"s were");

Hardly close to correct; operator precedence dictates an implict
parethesization of:

       printf("%d file%s copied\n", nfiles, nfiles=(1?" was":"s were"));

The "or" branch of the conditional will therefore never be taken.  
You surely want `==' where you have `=' right now.

--tom
--
"UNIX was not designed to stop you from doing stupid things, because
 that would also stop you from doing clever things." -- Doug Gwyn




Sat, 14 Aug 1993 06:29:44 GMT  
 Printing plural forms.
[about annoying program output]

Quote:
> >>   1 files were copied
> >> when it should have been:
> >>   1 file was copied
>        printf("%d file%s copied\n", nfiles, nfiles=1?" was":"s were");
> This assumes that "0 files were copied" is correct.  For that reason, and
> because it's less susceptible to bonehead errors like mine, I prefer the
> second form, which gives "files copied: 0", "files copied: 1",...

Your second form ("files copied: n") is better for another reason: It will
prevent much tearing of hair if anyone attempts to translate the messages
to another natural language.

The ?: singular/plural hacks calling printf are cute for programs which
don't travel much, but they don't translate.  There's generally no hope for
any sort of automated rework, either.
--

   ...But is it art?



Sat, 14 Aug 1993 09:21:35 GMT  
 Printing plural forms.
|>      printf("%d error%s copied\n", nfiles, nfiles?"s were":" was");

Here you must assume your program is never going to be altered so as
to be usable by a non-English speaker.  Otherwise, you've given them
the job of not only finding all embedded strings and directly
translating them, but also recoding to allow for different grammatical
constructions.

Of course, if you prepared for internationalization you'd use other
techniques anyway.

|>      printf("files copied: %d\n", nfiles);

Another reason to prefer this.

--

Systems Engineering, OSF                uunet!osf.org!dbrooks
"It's not easy, but it is simple."



Sun, 15 Aug 1993 01:40:05 GMT  
 Printing plural forms.

Quote:


>>> We all have seen and, in various degrees, been irritated by texts such
>>> as:
>>>    1 files were copied
>>> when it should have been:
>>>    1 file was copied

>>> I'd like to know: when programming, how do you avoid such errors?

>I stuck my coding pencil in my ear:
>>      printf("%d error%s copied\n", nfiles, nfiles?"s were":" was");
>> or
>>      printf("files copied: %d\n", nfiles);
>Several persons emailed to point out one or more of the the obvious errors
>in the first one.  I would correct it to

          printf("%d file%s copied\n", nfiles, nfiles=1?" was":"s were");
-----------------------------------------------------^
you mean ==
8^)
--
======= !{sun,psuvax1,bcm,rice,decwrl,cs.utexas.edu}!shell!rjohnson =======
Feel free to correct me, but don't preface your correction with "BZZT!"
Roy Johnson, Shell Development Company


Sat, 14 Aug 1993 23:25:35 GMT  
 Printing plural forms.

Quote:


>[about annoying program output]
>> >>       1 files were copied
>> >> when it should have been:
>> >>       1 file was copied
>>        printf("%d file%s copied\n", nfiles, nfiles=1?" was":"s were");

Think about us, poor Russians, I have to write something like:

        {
                char *p = "failov skopirovano";

                if( n < 10 || n > 20 )
                        switch( n % 10 ) {
                            case 1:
                                p = "fail skopirovan";
                                break;
                            case 2: case 3: case 4:
                                p = "faila skopirovano";
                                break;
                        }
                printf("%d %s\n", n, p);
        }

Got the point? I've spent a hell lot of time making bilingual release
of Unix (Russian and English) and finally I think it would be better
to have a standard function for producing plural forms, something like:

        printf("%d file%s copied\n", n, plural(n, ":s", "english"));

        printf("%d fail%s skopirovan%s\n", n, plural(n, "ov::a", "russian"),
                                              plural(n, "o::o", "russian"));

I have some ideas about how to handle plural forms and multilingual
diagnostics on binary installations but it requires a lot of changes
in compilers, languages, link editors and kernels. It's a long
story but it is possible.

Vadim Antonov
DEMOS, Moscow, USSR



Sun, 15 Aug 1993 00:12:56 GMT  
 Printing plural forms.

Quote:

> >> We all have seen and, in various degrees, been irritated by texts such
> >> as:
> >>   1 files were copied
> >> when it should have been:
> >>   1 file was copied

> >> I'd like to know: when programming, how do you avoid such errors?
>  ...
>  Which all goes to show: simpler is better.  The "files copied: %d" version
>  has been error free since the beginning--as far as I know.

As an addendum to this discussion, you might consider how these sorts
of problems occur when a program is internationalized (that is, converted
into another language) (that is, a human language other than English).
A truly "world class" (pun intended) programmer will consider such
issues during development.

As an example of the kind of problem that you can get into,
consider a printf() like this:
        printf("Your account balance on %s is %s\n", balance, date);

Assuming that you pull the 1st argument out into a #define in a header
or a text file somewhere, at least the following other issues come up:
        1. How to print the correct currency symbol?
        2. How to format values > 999?
        3. How to format the date?
        4. Whether, in a language other than English, would
        the message read more sensibly with the second and
        third printf() arguments reversed?      

The ANSI C standard library (in a hosted implementation)
addresses the first three points [Doug, no need to respond
on those points unless I've screwed something up], but not the last.
HP's prinf() family contains some extensions for this purpose.
I'm not aware of any other vendor that has attacked this issue.

Dave Wolverton

...!att!honshu!daw



Sun, 15 Aug 1993 06:49:00 GMT  
 Printing plural forms.

Quote:

>> [discussion of pluralization deleted]
>As an addendum to this discussion, you might consider how these sorts
>of problems occur when a program is internationalized (that is, converted
>into another language) (that is, a human language other than English).
>A truly "world class" (pun intended) programmer will consider such
>issues during development.
>Assuming that you pull the 1st argument out into a #define in a header
>or a text file somewhere, at least the following other issues come up:
>        1. How to print the correct currency symbol?
>        2. How to format values > 999?
>        3. How to format the date?
>        4. Whether, in a language other than English, would
>    the message read more sensibly with the second and
>    third printf() arguments reversed?      

Acting as a Lisp gadfly, my response would be "Too bad you don't
program in a language with a real object system, in which the solution
would be to have dates, currency amounts and so forth each know how to
form their own printed representation.  One would then have subtypes
of DATE such as EUROPEAN-DATE, and subtypes of CURRENCY-AMOUNT such as
RUBLE, DUETSCH-MARK and DOLLAR."

Such an implementation has other wins as well.  For instance, if
currency amounts are represented as numbers, it gets very inconvenient
to represent $19.99.

Of course, one often wants more light-weight representations of such
things, in which case the appropriate thing to do is program in an
object-oriented manner even if you don't use explicit objects.
--

"You ever think about .signature files? I mean, do we really need them?"
  - alt.andy.rooney



Mon, 16 Aug 1993 00:19:25 GMT  
 
 [ 24 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Internationalization [was Re: Printing plural

2. Internationalization [was Re: Printing plural

3. Printing to a Pre-Printed Form

4. Plural of VI

5. Tip of the day (handling plurals)

6. easy plural formatting question

7. Printing dollar amounts on forms

8. Printing routine for APL+WIN Forms

9. Using pre-printed forms - what approach to take?

10. printing on preprinted forms

11. Printing label without form feed C5b ABC

12. Print single space on form templete

 

 
Powered by phpBB® Forum Software