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

World: r4wp

[!REBOL3] General discussion about REBOL 3

MarcS
14-Mar-2013
[2039x2]
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?
Ladislav
15-Mar-2013
[2071x2]
My tests are actually "preconditions" at least in the specification, 
but due to the overflow possibility I converted them to one precondition 
and one postcondition to be able to handle the arithmetic issues 
before they occur.
once the condition allows another evaluation, I already know that 
the overflow does not occur and I can increment without taking any 
risk
Gregg
15-Mar-2013
[2073x3]
You lost me. Do you mean CFOR can't spare the effort to do the checks, 
or you can't spare the effort to create a version of FOR that uses 
CFOR?
If Brian is OK with your new FOR, I think I am as well. I am also 
happy to refine my new LOOP func more, if people think there is value 
in it; as an alternative.
And I assume you will add support for other datatypes back into your 
FOR, beyond integers.
Ladislav
15-Mar-2013
[2076]
You lost me.
 - sorry, this looks to be caused by my bad English this time
 Do you mean CFOR can't spare the effort 

 - actually, CFOR (its implementation) does not need to handle such 
 issues leaving that to the programmer to handle only when needed


regarding the "I do not think it could spare any effort" - the sentence 
should probably look as follows: "I do not think it (implementing 
FOR using CFOR) could save any effort"
Gregg
15-Mar-2013
[2077]
Thanks for clarifying. And rememeber how much better your English 
is than my Czech. :-)


My LOOP, using CFOR, is slower to set up, but much faster in the 
loop than FOR (incl your new FOR), so I thought it might be worth 
it.
Ladislav
15-Mar-2013
[2078x2]
aha, interesting, did not make any measurements
Would not have guessed that to be the case. Then it really may be 
worth trying.
Gregg
15-Mar-2013
[2080]
loop - 1 - 100'000 calls 0:00:02.108
for - 1 - 100'000 calls 0:00:00.508
loop - 1'000'000 - 1 call 0:00:00.304
for - 1'000'000 - 1 call 0:00:01.122
Ladislav
15-Mar-2013
[2081]
I suppose you use R2?
Gregg
15-Mar-2013
[2082x7]
Yes.
Let me see if I can test real quick with R3. My timing func uses 
LOOP. :-)
R3 results:
loop - 1 - 100'000 calls 0:00:01.539
for - 1 - 100'000 calls 0:00:00.683
loop - 1'000'000 - 1 call 0:00:00.358
for - 1'000'000 - 1 call 0:00:01.144
No special handling in mine for decimal step values. So under R3, 
that test will show this:
[loop [i 0 1 0.2] [print i]]
0
0.2
0.4
0.6000000000000001
0.8
1.0
For those not following closely, the discussion about FOR is trying 
to clarify and document its behavior, while keeping it easy to use 
(e.g., avoid accidental infinite loops). Ladislav has also asked 
for better names for CFOR, his general loop func that is efficient 
and flexible, but requires a bit more care in use. There is also 
a general consensus that FOR takes more args than we would like, 
while noting that we have other looping funcs we can use in most 
cases.


I propose a new LOOP implementation that is compatible with the current 
LOOP func (and delegates to it internally), while also providing 
a dialected interface which is a wrapper to CFOR.
Goals:

* Provide a general loop that is both friendly and flexible
* Support multiple datatypes as FOR does today
* Use CFOR internally for efficiency
* Adhere to the latest model discussed here and on CC
Interface:

LOOP compatible
    [loop 5 [print "x"]]
REPEAT compatible
    [loop [i 5] [print i]]
CFOR compatible (except for all args being in a block)
    [loop [[i: 1] [i <= 1000] [i: i + i]] [print i]]
FOR compatible (except for all args being in a block)
    [loop [i 5 10 2] [print i]]
Like FOR, but with a default bump of 1
    [loop [i 5 10] [print i]]
Or -1 if start is greater than end
    [loop [i 10 5] [print i]]