Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!rpi!batcomputer!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.misc Subject: Re: Printing plural forms. Message-ID: <4862@goanna.cs.rmit.oz.au> Date: 1 Mar 91 08:00:45 GMT References: <1991Feb19.104810.549@ZYX.SE> <2706@kraftbus.cs.tu-berlin.de> <6479@skye.cs.ed.ac.uk> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 72 In article <6479@skye.cs.ed.ac.uk>, nick@cs.edinburgh.ac.uk (Nick Rothwell) writes: > In article <1991Feb20.001242.9592@Think.COM>, barmar@think.com (Barry Margolin) 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). The DEC-10 Prolog library has a command writef(Format, [X1,...,Xn]) which has as one of its features "% j" where is an integer defining the language rules to use. Why "j"? Well, it's the obvious choice for Esperanto... Why is there no Common Lisp format that optionally adds "ob", the Quechua plural suffix? Why is the distinction only between singular and plural -- what happened to the dual number? For English, how about the words borrowed from French that add an "x"? I think that it is unrealistic to expect a formatting sublanguage to handle the complexities of human languages. The best I've been able to come up with is void print_variant(number, stem, singular, dual, plural) int number; char *stem, *singular, *dual, *plural; { printf("%s%s", stem, ( number == 1 ? singular : number == 2 ? dual : plural )); } This can be packed, using TAB to separate [TAB [TAB [TAB ]]] -- default plural: empty "sheep" -- default singular: empty "cow s" -- default dual: same as plural "m en an" void print_variant(number, string) int number; char *string; { char *p, *q; p = strchr(string, '\t'); if (p == NULL) { printf("%s", string); return; } printf("%.*s", p-string, string); string = p+1; p = strchr(string, '\t'); q = p == NULL ? NULL : strchr(p+1, '\t'); /* plural p>TAB singular q>TAB dual or plural p>TAB singular NUL; q==NULL or plural NUL; p==q==NULL */ if (number == 1) { if (p == NULL) return; if (q == NULL) printf("%s", p+1); else printf("%.*s", q-p-1, p+1); } else if (number == 2 && q != NULL) { printf("%s", q+1); } else { if (p == NULL) printf("%s", string); else printf("%.*s", p-string, string); } } So printf("%d", NFiles); print_variant(NFiles, " file\ts were\t was"); printf(" deleted.\n"); One could perhaps add this to something like C, where %j would take n as the number, and the string from the argument list, getting xprintf("%d %*j deleted.\n", Nfiles, NFiles, "file\ts were\t was"); -- The purpose of advertising is to destroy the freedom of the market.