🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #2858

Re: Printing plural forms.

#2858
From: Richard A. O'Keefe
Date: Fri, 01 Mar 1991 08:00
72 lines
3109 bytes
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 "% <n> j" where <n> 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 
	<stem> [TAB <plural> [TAB <singular> [TAB <dual>]]]
	-- 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 %<n>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.
Technical Details
Message-ID: <4862@goanna.cs.rmit.oz.au>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!rpi!batcomputer!munnari.oz.au!goanna!ok
References: <1991Feb19.104810.549@ZYX.SE> <2706@kraftbus.cs.tu-berlin.de> <6479@skye.cs.ed.ac.uk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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