• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[!REBOL3] General discussion about REBOL 3

Ladislav
12-Mar-2013
[1709x3]
I gave the

    for i 1 2 0 [prin "x"]


a second thought, and the fact is that the "forever" functionality 
looks legitimate as well. Thus, it would be best if we made a user 
poll to find out what is preferred. Whether looping forever or not 
looping at all. So, please, let us know what do you prefer.
Alternatives are:


1) for i 1 2 [prin "x"] loops forever printing "infinite" string 
xxx....
2) for i 1 2 [prin "x"] does not loop at all yielding none

Consistently, we want to see the same behaviour when encountering

for i 2 1 0 [prin "x"]

or

for i 1 1 0 [prin "x"]
Pekr, I hope that you do express your preference as well.
GrahamC
12-Mar-2013
[1712]
shouldn't a for loop run at least once, and then on the next run 
check to see if limits are exceeded?
Ladislav
12-Mar-2013
[1713x2]
That is a matter of preferences as well (at least IMO). You can have 
such preference and express it, but another legitimate wish is for 
this case:

    for i 2 1 1 [prin "x"]

to not run at all yielding #[none] as it currently does in R3
So, Graham, I did not understand your question as an expression of 
your preferences. So, you still have an oportunity to express what 
your preferences are.
Pekr
12-Mar-2013
[1715]
well, I can imagine more scenarios, and it needs some thought to 
stay consistent between the cases. So my first thoughts, starting 
with the latest example:

for i 2 1 1 [prin "x"]


If above scenario means returning #none (and I agree with that), 
then I think that the for i 1 2 0 [print "x"] could be just the same. 
But - it might be related to the thoughts of the indexing. In REBOL 
series (if I am right), the position is in between the elements (not 
on the first element). So in that regards, skip 0 moves nowhere. 
But - it might also mean (as "first series" returns first element), 
that it should perform the loop just once. 


The last option for me is to cause an infinite loop, although from 
some point of view, it might make some sense too - you simply want 
to traverse the range, from 1 to 2, but you skip 0. If you would 
use just 'skip, you would cause an infinite loop. So - I really don't 
know ....
Ladislav
12-Mar-2013
[1716x3]
Well, I do not require you to invent or justify how it should work. 
I think that it really may be just a matter of preference. So, you 
just need to tell what it is you would find the most convenient behaviour 
when writing the

    for i 1 2 0 [prin "x"]

in your code.
Of course, there is an option that you just do not mind, since you 
do not intend to write such an expression at all.
(actually, in that case you might prefer the interpreter to cause 
an error for you to inform you that you did something you did not 
intend to do)
GrahamC
12-Mar-2013
[1719]
I prefer at least one execution.  If 0 is the loop increment, then 
it is a forever loop unless the loop parameters are also both 0
Ladislav
12-Mar-2013
[1720]
Thanks, Graham, counted.
GrahamC
12-Mar-2013
[1721]
so for i 0 0 0 [ .. executes only once ]
Ladislav
12-Mar-2013
[1722]
Aha, hmm, that is a problem. If

    for i 1 2 0 [prin "x"]

loops forever, I would expect that e.g.

    for i 1 1 0 [prin "x"]

behaves exactly the same way looping forever as well.
GrahamC
12-Mar-2013
[1723]
execute once, increment the loop counter and then check it against 
the upper bounds.
Ladislav
12-Mar-2013
[1724]
Yes, but it is in the bounds still.
GrahamC
12-Mar-2013
[1725]
so, in the first instance it's forever, the second is just once
Ladislav
12-Mar-2013
[1726]
You cannot get out of bounds adding 0.
GrahamC
12-Mar-2013
[1727x3]
>= to the upper bound
so that would be two iterations
hmm.. what happens with negative increments
Ladislav
12-Mar-2013
[1730]
so that would be two iterations
 - if I understand it well that looks like a preference shift.
GrahamC
12-Mar-2013
[1731x2]
execute once, increment counter from start, if counter is <= outer 
bound execute again.  if counter is now >= outer bound exit
we are allowed to alter the counter value inside the loop right?
Ladislav
12-Mar-2013
[1733]
if counter is now >= outer bound exit

 - however, that requires to use two distinct tests for iterations 
  (in the first case the upper bound is included in the range since 
 upper-bound <= upper-bound, while in the second test the upper bound 
 is excluded from the range since upper-bound >= upper-bound)
GrahamC
12-Mar-2013
[1734]
that would allow us to break out of a forever loop
Ladislav
12-Mar-2013
[1735x3]
Yes, we are:

* allowed to use BREAK
* allowed to change the cycle variable inside the body
So, a forever loop is not a problem when you do not think it is a 
problem
Regarding the negative bump versus the positive bump:


* I tend to think that the set of integers specified by start-bound 
1 end-bound 3 and bump 1 to contain the numbers [1 2 3] 

* I tend to think that the set of integers specified by start-bound 
3 end-bound 1 and bump -1 to contain the numbers [3 2 1]

* judged this way the set of integers specified by start-bound 1 
end-bound 3 and bump 0 may be considered
** incorrectly specified (cause error)

** empty since it does not specify correctly a nonempty set of integer 
numbers (do not loop)
** it may be specially defined as [1 2 3] (infinite loop)


Choosing an alternative of the above three I consider just a matter 
of preference.
Endo
12-Mar-2013
[1738x4]
In many other languages it leads to infinite loop.
It looks like (on R3) it checks the upper bound if the bump value 
is positive, lower bound if the bump value if negative
AND if the bound value can be reachable with the bump value.
for i 5 3 0  [i: 2 print i] ;==2, stop
for i 5 3 0  [i: 6 print i] ;==6, infinit
this is not consistent with 
>> for i 3 5 0  [i: 6 print i] ;== none
>> for i 3 5 0  [i: 2 print i] ;== none
Ladislav
12-Mar-2013
[1742]
Yes, that is the inconsistency described above.
Endo
12-Mar-2013
[1743x5]
in the first example, it checks the right-bound-value.
So if the bump value is zero, then it should check;
* always the right-bound
* or the lower one.

>> for i 5 5 0  [i: 2 print i] ;==2, stop.
I mean "decide the direction by looking at the bounds" then "check 
the bump value, if it is possible to reach that bound value (check 
the direction of bump value)"
if it is not reachable, return none without executing the block.
This can cover all the possibilties, pos., neg. or zero bump value.
Ladislav
12-Mar-2013
[1748]
I understand you, and youi gave some inspiration, but you used some 
terms that may be rather confusing:

right bound
 - did you mean the END value?
lower bound
 - did you mean the START value or the minimum of START and END?
Endo
12-Mar-2013
[1749]
Yes that was what I mean, sorry, English is not my main language, 
so it is a bit difficult what I exactly mean.
Ladislav
12-Mar-2013
[1750x3]
No problem, I just wanted to make sure.
this still leaves an uncertainty whether we want to handle the situation 
of

    for i 1 2 0

the same as

    for i 1 1 0
BTW, END and START I did not mean as English words. I meant them 
as the respective FOR parameters.
Endo
12-Mar-2013
[1753]
according to my explanation, both should return none, because end 
value is not reachable.
Ladislav
12-Mar-2013
[1754]
hmm, but 1 = 1 + 0, i.e. the END value actually is reachable in the 
latter case
Endo
12-Mar-2013
[1755x4]
Yes, if step is negative START - END should be swapped.
aha, second case, you are right.
wait, it should pass the END value.
For i=1 To 1 Step 0 --> infinite loop on  BASIC.
Normally, in old BASICs languages, variable used in FOR, its value 
stays END+1 at the end of the loop.