Ladislav,

That is an impressive For function!
your example of using
>a: [1 2]
>for s a tail a 1 [print s]
as a test is very amusing bug, looks 
like an infinite loop on windows, just 
keeps printing newlines without ever ending.

Just for kicks, I just tried this:
>> for s a back tail a 1 [print s]
1 2
2

so that it stops at the last real position,
and that seemed to work, althout the expression 
is more awkward and wordy!

Your other example is this:
>> for s a next a -1 [print s]
1 2

which I am not sure I get.
This would never get to next a by skipping -1.
Either you have a typo here, or I missed the point.

If this were integers, it would look like
for x = 1 30 step -1

>> for s a next a 1 [print s]
1 2
2

What is the proper behavior of
>> for s a next a -1 [print s]
???

-Galt

p.s. As far as the second-class vs. first-class values 
goes, I am inclined to agree with you.  There are some 
fishy issues that don't seem entirely cooked.  You are 
right to bring them up for discussion.  So far, however, 
in the programs that have come up naturally in my 
use of Rebol, I haven't been banging into these issues
alot.  I have seen the errorhandling stuff e.g. try, disarm
seems like it's more awkward than it should be.
I could run smack into more of them at any moment, 
though!

p.p.s.  I think the desire to share Rebol data and 
objects across the net between two instances of rebol.exe,
or storing them and retrieving them later in native Rebol format,
will come up strongly in the near future.  
Even the RebMail program might be a lot simpler if 
you could just save your mail objects and reload later.
Having to create extra functions for converting from 
Rebol to some other disk structure and then back 
again is a pain.  I think Rebol can do better.
It just needs to make a few new tricks available...





>===== Original Message From "Ladislav Mecir" <[EMAIL PROTECTED]> =====
>2. For loop. Here is my version working properly for series (just
>a minor improvement):
>
>Nobody uses For to traverse a series, I guess. OTOH, the
>implementation of For should be correct.
>
>; Example of incorrect behaviour:
>a: [1 2]
>for s a tail a 1 [print s]
>for s a next a -1 [print s]
>
>My correction:
>
>for: func [
>    {Repeats a block over a range of values.}
>    [catch throw]
>    'word [word!] {Variable to hold current value}
>    start [number! series! money! time! date! char!] {Starting
>value}
>    end [number! series! money! time! date! char!] {Ending value}
>    bump [number! money! time! char!] {Amount to skip each time}
>    body [block!] {Block to evaluate}
>    /local result do-body op cond
>][
>    if (type? start) <> (type? end) [
>        throw make error! reduce ['script 'expect-arg 'for 'end
>type? start]
>    ]
>    do-body: func reduce [[throw] word] body
>    op: either positive? bump [:greater-or-equal?][
>        :lesser-or-equal?
>    ]
>    either series? start [
>        if not same? head start head end [
>            throw make error! reduce ['script 'invalid-arg end]
>        ]
>        cond: op index? end index? start
>        while [cond] [
>            set/any 'result do-body start
>            cond: op index? end (index? start) + bump
>            start: skip start bump
>        ]
>    ] [
>        while [op end start] [
>            set/any 'result do-body start
>            start: start + bump
>        ]
>    ]
>    get/any 'result
>]
>

Reply via email to