[REBOL] Re: Rebol vs Ruby
From: rebol:techscribe at: 21-Dec-2000 0:16
Hi chaz,
I think that using parse is overkill in this situation. Here's pretty
much your code which replaces the parse rule and the use of parse by
using the following construct:
foreach line table [
set [unit singular plural] line
Here's the complete modified code:
REBOL []
table: [
[31557816 "year" ]
[2629818 "month" "rewarding months"]
[86400 "day" ]
[3600 "hour" "enjoyable hours"]
[60 "minute" ]
[1 "second" ]
]
time: 2629818 + 2629818 + 2629818 + 3600 + 3600 + 15
; I expect the output "3 rewarding months 2 enjoyable hours
; 15 seconds"
result: ""
foreach line table [
set [unit singular plural] line
if not plural [ plural: rejoin [singular "s"] ]
size: time / unit
; We want to take the integer part of size and compare it to 1 to
; determine if we need to use the singular or plural form.
if (to-integer size) > 0 [
result: rejoin [
result size " "
either size = 1 [singular][plural]
" "
]
time: time // unit
]
]
print result
chaz wrote: