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

World: r4wp

[!REBOL3] General discussion about REBOL 3

Sunanda
14-Mar-2013
[2021]
Sorry.......As I said, some false hits - no easy way to exclude
    comment [....]
from searches.
When I said it excluded comments, I meant
    ; comment
Ladislav
14-Mar-2013
[2022x7]
understood, no problem
Brian, =end is not a termination condition, see these examples:

for i 5 5 1 [print i i: -5] ; this should print 5 and terminate
for i 5 5 1 [print i i: 3] ; this should be print 5 and terminate
for i 5 5 1 [print i i: 4] ; this should be an infinite loop
for i 5 5 1 [print i i: 5] ; this should print 5 and terminate
for i 5 5 1 [print i i: 6] ; this should print 5 and terminate
It is quite funny that you read what I wrote in the ticket but have 
got no idea what the differences are
similar examples for negative BUMP:

for i 5 5 -1 [print i i: 3] ; this should print 5 and terminate
for i 5 5 -1 [print i i: 4] ; this should print 5 and terminate
for i 5 5 -1 [print i i: 5] ; this should print 5 and terminate
for i 5 5 -1 [print i i: 6] ; this should be an infinite loop
for i 5 5 -1 [print i i: 7] ; this should print 5 and terminate
and as I said for zero bump you do not have any reasonable termination 
condition to use that would allow you to iterate at least once but 
not infinitely many times by default, so you just have to terminate 
before starting
Your problem is that you did not realize that the only way how to 
stop *before* starting is to apply the termination condition *just 
before* entering the cycle body
and, of course, it is immediately obvious why =end is not a termination 
condition then
PeterWood
14-Mar-2013
[2029x2]
Is this a bug?

>> val: [a b c]
== [a b c]

>> val = [a b c]
== true

>> switch val [[a b c] [1]]  
== none
The 'swtich doc string doesn't indicate any restriction on the type 
whch can be used as the switch value.
Sunanda
14-Mar-2013
[2031]
Looks a bit odd.....

In R2 it doesn't work if the val is a block! but it does with hash!
In R3, block! doesn't work but map! does

Test code:
   val: make map! [1 2 3 4] switch val reduce [val [print 1]]
PeterWood
14-Mar-2013
[2032]
Should I add it to curecode?
Gregg
14-Mar-2013
[2033]
%new-loop.r updated with Ladislav's latest examples.
Ladislav
14-Mar-2013
[2034]
BTW,

    for i 1 1 0 [print i]

is an infinite cycle both in R2 as well as in R3
Bo
14-Mar-2013
[2035]
BrianH: I used 'for quite a bit in R2.  But I used it simply when 
I needed access to a counter.
BrianH
14-Mar-2013
[2036x2]
Ladislav, you are not getting that I am applying an *additional* 
termination condition before the start of the first loop, in addition 
the normal termination condition applied after every iteration of 
the loop, before the bump. Please don't mistake an intentional constraint 
for confusion.
I am not at all confused by your argument, I just don't agree with 
it.
MarcS
14-Mar-2013
[2038x3]
Proposed fix for http://curecode.org/rebol3/ticket.rsp?id=1979- 
https://github.com/0branch/r3/commit/5bc79f6812a67f28ccd79372361c7fad7f3a6ea0
The linear search isn't ideal, though it means that existing structures 
can be re-used without further allocation.
Now https://github.com/rebol/r3/pull/105
Ladislav
14-Mar-2013
[2041x3]
'Ladislav, you are not getting that I am applying an *additional* 
termination condition before the start of the first loop, in addition 
the normal termination condition applied after every iteration of 
the loop, before the bump. Please don't mistake an intentional constraint 
for confusion.'  a couple of notes:


- you still don't get that if you are not consistent producing a 
lot of exceptions your code will be full of bugs and arbitrarinesses 
(there is absolutely no escape from this)

- you still don't get that there are concrete examples above demonstrating 
the problems you did not even consider yet
And I am not mentioning other problems I did not even discuss yet.
Also, saying that a cycle runs exactly once (which is, thus, independent 
on the cycle body) is too inflexible to not be considered just a 
bug  when knowing that the cycle varialble may be adjusted in the 
cycle body
Gregg
14-Mar-2013
[2044x2]
Brian, on CC, your latest note links to #864, which I think should 
be #884.
Brian and Ladislav, how can we resolve this? Maybe you could both 
look at %new-loop.r and it would unite you against my incorrect and 
overly complex attempt. :-)
Ladislav
15-Mar-2013
[2046x2]
:-)
Meanwhile, you can check this to compare:


https://groups.google.com/forum/?fromgroups#!topic/Rebol/appT3TV5urY
Gregg
15-Mar-2013
[2048]
>> for i 10 5 -1 [print i]
** Math Error: Math or number overflow
** Where: for
** Near: either max-int - bump <
Ladislav
15-Mar-2013
[2049]
needs correction, as it looks, checking
Gregg
15-Mar-2013
[2050]
Seems to be the same for all negative steps (quick test).
Ladislav
15-Mar-2013
[2051x4]
aha, I swapped the condition, try with either negative? bump, please
disregard, needs something else...
aha, it should have been max-int + bump
I shall put the code here
Gregg
15-Mar-2013
[2055]
I'll test it when you do.
Ladislav
15-Mar-2013
[2056]
done
Gregg
15-Mar-2013
[2057]
At a quick glance, I believe for FOR and my LOOP have the same behavior, 
though I didn't address overflow as an initial goal.
Ladislav
15-Mar-2013
[2058x2]
Yes, that is what I guessed
(but I did not test your LOOP, to be honest)
Gregg
15-Mar-2013
[2060x3]
And your approach with the bump overflow check is much cleaner.
You can just run it, and it will dump tests and output to the console.
And mine uses CFOR as the internal loop handler. As I noted briefly, 
it's just a dialect wrapper over CFOR.
Ladislav
15-Mar-2013
[2063x4]
That is no problem with me, but I know that CFOR does not need to 
handle overflow leaving that to the programmer if needed
(the important thing is that it is not needed in the great majority 
of cases)
However, FOR does not have this luxury
(which leads to slowness and overhead)
Gregg
15-Mar-2013
[2067x2]
Why can't you just convert FOR args to CFOR rules?
Internally.
Ladislav
15-Mar-2013
[2069]
I do not think it could spare any effort
Gregg
15-Mar-2013
[2070]
You mean the time to implement it?