I'm trying to figure out how to implement what I think that code does.
Unfortuately I get an error.
It looks like it's trying to parse a series of blocks. The blocks are in
the form of units of time measured in seconds, singular form of the unit,
and the plural form of the unit.
> table.each {|unit, sing, plur|
> plur = sing+'s' if !plur;
If the plural is absent, we assume that it is formed by adding s to the
singular form.
For instance the plural of "year" is "years", but perhaps, as in some
contrived situation like this, the plurals cannot be formed this way.
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: ""
rule: [
set unit integer!
set sing string!
set plur [none! | string!]
]
foreach line table [
; parse returns false if there is no plural entry
if not [parse line rule] [plur: rejoin [sing "s"]]
; Unfortunately the error occurs here
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][sing][plur]] " "]
time: time // unit
]
print result
chaz
At 01:25 PM 12/19/00 -0800, you wrote:
>Hi Galt,
>
>Ruby predates REBOL by a year or two (I've been on the Ruby mailing list
>much longer than REBOL's).
>
>IMHO you really cannot compare Ruby to REBOL. From a syntactic point of
>view Ruby (to me) is extremely cumbersome and cryptic. It is intended as
>a purely object oriented scripting language and reminds me of a mixture
>of Java and PHP. Here is a code sample submitted by Steve to the Ruby
>mailing list:
>
> #! /usr/bin/env ruby
> # Given the number of seconds, convert to English description
>
> table = [ [ 31557816, 'year' ],
> [ 2629818, 'month' ],
> [ 86400, 'day' ],
> [ 3600, 'hour' ],
> [ 60, 'min' ],
> [ 1, 'sec' ] ]
>
> result = ""
>
> time = ARGV[0].to_i
> table.each {|unit, sing, plur|
> plur = sing+'s' if !plur;
> size = time / unit
> if size > 0
> result += "#{size} #{(size == 1) ? sing : plur} "
> end
> time %= unit
> }
>
> puts result
>--
>
>[EMAIL PROTECTED] wrote:
>>
>> I have been away from the list for a while,
>> so forgive me if this has already been hashed to death.
>>
>> I just a few days ago ran across references to Ruby,
>> a newish programming language invented by a
>> man in Japan (Matsumoto something...) and it seems
>> to have many features similar to Rebol.
>>
>> http://www.ruby-lang.org/en/
>>
>> Anyway, as I was reading about it I started making
>> a rough comparison to rebol. Weird how similar
>> the names are. Anyway, let's see...
>>
>> They both have good web support, are interpreted,
>> support advanced data structures, have automatic garbage collection,
>> have context/closures, error-handling.
>>
>> Platform
>> Rebol ++ great, easy install, works on lots of platforms
>> Ruby - oriented towards unix, can work on windows with effort.,
>> only works in places like unix, and windows and dos and a few
>> other platforms which can cobble together unix-like behavior
>> with various add-on support modules.
>>
>> Multithreading
>> Rebol - I know the apache server has some threading, but not basic reb.
>> Ruby + good support for threads and semaphores
>>
>> Grpahics
>> Rebol + graphics available now, no charge, and platform indep., easy
to use
>> Ruby - still don't have it built in, only some links to tk and other
>>
>> unix libs Open Source
>> Rebol - no open source
>> Ruby + strong open source community
>>
>> OOP
>> Rebol ? rebol objects don't have real inheritance, you can do useful
stuff,
>> but they often just act as nice containers.
>> Ruby + everything is an object, this is real oop, albeit
single-inheritance.
>> (personally, I don't care that much about oop, but if you do, you
will like Ruby's oop)
>>
>> Performance
>> Rebol ? Performance boosted at the loss of continuations and other
niceties.
>> Ruby ?- Probably has perf. not quite as good, but still pretty good, and
>> they haven't jettisoned continuations, which is cool.
>>
>> Packages - modules for large sw dev.
>> Rebol ? I haven't been following, but Rebol's are improving all the time
>> Ruby + they seem to have good support for modules/libs/namespaces
>>
>> Size
>> Rebol ++ Nice and small and easy to install
>> Ruby ? Not sure how big, but probably not small like Rebol.
>>
>> Syntax
>> Rebol + I like Rebol's syntax, don't suffer from endless parentheses
and ;
>> Ruby -? Pretty good syntax, but lots of "end" keywords everywhere
>>
>> Closures
>> Rebol - Boo, hoo, I miss them
>> Ruby + Yeah, they still got 'm
>>
>> Web Protocols
>> Rebol + built in, could often use better doc. and examples,
>> and some stuff like support for cookies is still lame addon
>> Ruby ? seem to have good stuff, but as external package
>> it is not quite as built in and ready to go, but still not bad.
>>
>> Object Serialization (saving and sending 'em)
>> Rebol - nothing on the map yet, and it would add a whole new
>> dimension, but problems as the definition of "binary" data
>> and other types is not defined.
>> Ruby + apparently, it is supposed to have good support for
>> serializing objects, which is pretty cool.
>>
>> List as fundamental data element
>> Rebol + has them built in, and very useful with good performance.
>> Ruby ?- has great object support, but list support is an
>> afterthought not an inherent tool.
>>
>> Ability to Link Foreign Code
>> Rebol ? can do somewhat with Rebol/Command only?
>> Ruby + supposed to excel at this
>>
>> Perl-like features
>> Rebol + doesn't have 'em, I don't like perl much
>> Ruby ?- partly Ruby was invented as a much better perl,
>> has perl-like features
>>
>> Built-in utility features
>> Rebol +/- platform isolation, but then you can't access some file
attributes, etc.
>> Ruby + supposed to be strong at this, although very unix-oriented
>>
>> Cost
>> Rebol +? Not expensive, basic rebol and /view are free!
>> Ruby + Hard to beat free
>>
>> Globalization support
>> Rebol ? I always wondered why Rebol was not designed for an
>> international global world. Only ascii support apparently at this
time.
>> Ruby + Partly because it's inventor is Japanese, this language is
>> supposed to have excellent support built-in for handling lots of
>> languages way beyond just plain 256 ascii codes.
>>
>> Well, you know I am extremely fond of Rebol,
>> but it looks like Ruby has the edge in a few areas.
>> While it is harder to install and runs on fewer platforms,
>> lacks built-in graphics and simple installation, it does
>> however have full oop, perl (yuck), good library/ext packages,
>> international lang. support, serialization, and closures,
>> and free open source with strong user community.
>>
>> I am sure some of you have run into this language,
>> what do you think of Rebol vs. Ruby and the future?
>>
>> Note - I am just curious, not interested in flame-fights,
>>
>> and would like to know what some of the intelligent folks on
>> the list here think about it.
>>
>> -Galt
>>
>> --
>> To unsubscribe from this list, please send an email to
>> [EMAIL PROTECTED] with "unsubscribe" in the
>> subject, without the quotes.
>--
>To unsubscribe from this list, please send an email to
>[EMAIL PROTECTED] with "unsubscribe" in the
>subject, without the quotes.
>
>
--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without the quotes.