Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: for bug?

From: joel:neely:fedex at: 17-Jun-2002 7:44

Hi, Romano, Romano Paolo Tenca wrote:
> My point of view is that if 'for accepts unsigned integer, > it must know how to handle them. > > In my expression i have asked to stop at 255 not at > something > 255. I think that 'for should be an until loop: > > until [ > ... > i >= 255 > ] > > not a while loop: > > while [i > 255][
i <= 255 ;; just a typo
> ... > ] > > else 'for couldn't handle unsigned value in the right mode > and it should not accept values it does not know how to handle. >
The problem with post-condition tests is their inability to do nothing gracefully . In the case
>> for i 3 2 1 [print i]
== none which can be understood as print each number i in the range [3 <= i <= 2] stepping by 1 nothing should print, because the range is empty.
> But perhaps others languages have this limitation in their for > loop with unsigned values. Joel do you confirm this? >
The issue is not unsigned values, but rather what happens at the edge of a finite domain (and, with programming, all elementary domains are finite... ;-) Consider the following:
>> for i 2147483640 2147483647 1 [print i]
2147483640 2147483641 2147483642 2147483643 2147483644 2147483645 2147483646 2147483647 ** Math Error: Math or number overflow ** Where: for ** Near: start: start + bump versus
>> a: #"^(fa)"
== #""
>> loop 6 [print mold a: a + 1]
#"" #"" #"" #"" #"" #"^@" versus
>> a: 255.255.255.250
== 255.255.255.250
>> loop 6 [print a: a + 1]
255.255.255.251 255.255.255.252 255.255.255.253 255.255.255.254 255.255.255.255 255.255.255.255 So, REBOL handles hitting the limit of a domain in at least three distinct ways, depending on type: 1) throwing an error integer! 2) wrapping within domain char! 3) "sticking" at the limit tuple! Anyone know of any others? IMHO any effort to redefine the behavior of FOR should address the following issues: - REBOL's use of strongly-typed values (e.g. (#"^(ff)" + 1) evaluates to char! rather than widening to integral 256) - the ability to do nothing gracefully - the handling of limit values - minimizing overhead (maximizing performance) I don't have a good answer at this point, but we are talking about a limited number of special cases where this happens (max values for the types {number series money time date char}). -jn- -- ; Joel Neely joeldotneelyatfedexdotcom REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] { | e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]