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: 16-Jun-2002 16:42

Hi, Romano, It has to do with (non-intuitive IMHO) handling of arithmetic on character values... Romano Paolo Tenca wrote:
> In a console > > for x #"^(00)" #"^(ff)" 1 [print to integer! x] > > -> endless loop >
No matter how many times you add 1 to a character value, it will never be greater than #"^(ff)" (believe it or not!)
>> foo: #"^(ff)"
== #"ÿ"
>> foo + 1
== #"^@"
>> to-integer foo + 1
== 0 You might have been expecting that
>> (to-integer foo) + 1
== 256 would cause the loop to exit once the counter had exceeded the stated upper bound, but...
>> to-char (to-integer foo) + 1
** Math Error: Math or number overflow ** Where: to-char ** Near: to char! :value On the other hand, for x to-integer #"^(00)" to-integer #"^(ff)" 1 [print x] works just fine, and you can use the phrase to-char x inside the body of the FOR if you really wanted to do something with all possible character values. -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 ]