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/