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

My favourite functions, #1 Plural()

61 views
Skip to first unread message

Swifty

unread,
May 19, 2013, 2:56:04 AM5/19/13
to
I revel in the pleasure that I get from adding really useful routines to
my library (subroutines.rex) for use in Object Rexx.
Hoping to spread some of this pleasure around, I'm going to describe a
few of the functions, starting with plural()

I really dislike programs which generate statements such as:

7 item(s) found or 1 items found

So, I wrote plural() to cope with this. My code for the above message
might read:

Say plural(N,'item') 'found'

This, by itself is simple, but there are pitfalls...

Pitfall #1: When you are counting things like geese, where the plural is
more than an appended "s": 0 geese, 1 goose, 2 geese, etc.
Answer:
Say plural(N,'goose','geese')

Pitfall #2: You often want "no bugs found" rather than "0 bugs found"
Answer:
Say plural('N','bug',,'no')

Arguments from the 4th onward replace the corresponding 0,1,2,etc.

Here's my code:

::Routine Plural public
Parse arg n,word,plural
If arg() < N+4 | arg(N+4,'O') then name = N
Else name = arg(4+n)
If n = 1 then return name word
If plural <> '' then return name plural
Return name word's'

It's not commented as there's no point, I never look at it in practice.
My aid was conciseness.

My motive for posting this is to spread my happiness aroud, a little,
but in the process I discovered a bug in my code, so I also benefit! (I
wasn't handling omitted arguments in the 4th argument onwards)

--
Steve Swift
http://www.swiftys.org.uk/

LesK

unread,
May 19, 2013, 6:01:00 AM5/19/13
to
For you and I, native English (well, British and American) speakers,
that's a fine approach. However, it ignores the needs of those whose
primary language isn't English and who may not know the proper plural
form to pass as the third argument.

That's why I think my more general approach, that doesn't depend on
prior knowledge of English, is more usable by a wider audience. Even
though my code provides "exceptions to the rules", I _really_ like your
idea of providing an argument that goes beyond the exceptions. I'll try
to work that into my own code.

Interested parties can send me a private email for a copy of my
plural.rex - 275 lines (including 74 lines of added information), 8767
bytes. It can be used by Rexx and THE.

--

Les (Change Arabic to Roman to email me)

Swifty

unread,
May 20, 2013, 4:16:19 AM5/20/13
to
On 19/05/2013 11:01, LesK wrote:
> For you and I, native English (well, British and American) speakers,
> that's a fine approach.

I meant to acknowledge that the code would need modification for
languages otherthan English. However, the smallest step along that path
would complicate the code beyond belief!

I even balked at assuming the plural of ***y is ***ies as that
(presumably) would force the use of the third parameter (the plural
form) for some plurals which end in "ys".

I'll have to find a public group which discusses words now...

LesK

unread,
May 20, 2013, 5:14:00 AM5/20/13
to
It is, as you might say, "A sticky wicket". See the notes at the bottom
of the plural.rex that I sent you. I got them from the internet.

As always, there are tradeoffs to be made. :-)

Gil Barmwater

unread,
May 20, 2013, 1:24:28 PM5/20/13
to
I, too, dislike messages that include things like "7 item(s) found" so I
try not to generate them in my own programs. Since I'm the one writing
the message, I decided to keep the function simple and pass additional
arguments for the cases where the plural is not formed by adding an "s".

Some usages:
say 'Found' N 'item'?s(N)
say 'Found' N 'entr'?s(N, 'y', 'ies')
say 'Found' N ?s(N, 'goose', 'geese')

Here is the code for the function:

::routine ?s public
use arg n, s='', p='s'
?. = p
?.1 = s
return ?.n

Jeremy Nicoll - news posts

unread,
May 22, 2013, 2:58:57 PM5/22/13
to
Gil Barmwater <gbarm...@alum.rpi.edu> wrote:

> I, too, dislike messages that include things like "7 item(s) found" so I
> try not to generate them in my own programs.

I tend just to have lines of code like:

say "Number of geese found:" n

--
Jeremy C B Nicoll - my opinions are my own.

Email sent to my from-address will be deleted. Instead, please reply
to newsre...@wingsandbeaks.org.uk replacing "aaa" by "284".

Swifty

unread,
May 23, 2013, 1:31:33 AM5/23/13
to
On 20/05/2013 18:24, Gil Barmwater wrote:
> say 'Found' N 'item'?s(N)

Gosh! I've never thought of naming a function with a leading "?" � a
world of possibilities opens up.

My first take was that ?s() was some Object REXX syntax that I hadn't
come across, such as the use of the "~" character.

Gil Barmwater

unread,
May 23, 2013, 7:43:11 AM5/23/13
to
Swifty wrote:
> On 20/05/2013 18:24, Gil Barmwater wrote:
>
>> say 'Found' N 'item'?s(N)
>
>
> Gosh! I've never thought of naming a function with a leading "?" � a
> world of possibilities opens up.
>
> My first take was that ?s() was some Object REXX syntax that I hadn't
> come across, such as the use of the "~" character.
>
Others you may have missed: ! and _ as leading (or only) character. In
this case, ?s() has meaning (to me) as it questions whether to add an
's' to the preceding word. Also note you can use the function to choose
the correct form for verbs as well: ?s(N, 'was', 'were').

Swifty

unread,
May 23, 2013, 1:00:28 PM5/23/13
to
On 23/05/2013 12:43, Gil Barmwater wrote:
> note you can use the function to choose the correct form for verbs as
> well: ?s(N, 'was', 'were')

That possibility had not occurred to me. Thank you!

I was ever a stickler for grammatically correct output (from my
programs, rarely from my typing...) and this became my undoing. An
application that I'd written had copious code to handle the grammar of
the messages whicg it output. I'd developed the code over many years,
then got a request to translate it into a different language...
The effort would probably have exceeded the original application, but
fortunately retirement came to my rescue.
0 new messages