Comparing very long numeric strings

Jim Lyons jimlyons at earthlink.net
Tue Mar 16 17:10:04 EST 2004


I had very unexpected results from a fairly simple script. I have a 
long string of 1s and 0s in a variable representing the states of cells 
in a cellular automata simulation. There can be more than ten thousand 
cells. To detect when the CA is no longer changing, I save this string 
each cycle, then compare it with the string representing the next 
state:

     [ code to compute next state ]
     if nextState = curState then StopCA
     put nextState into curState
     showCA

Sometimes this worked, but many times the CA would stop before it 
should have; other times it would not stop when it should. I checked 
the code carefully, looked at the variables in the debugger, and looked 
in the docs for clues. Finally, I wondered if there could be a 
difference between numeric and string comparison, so I tried changing 
the comparison above to:

     if "z"&nextState = "z"&curState then StopCA

Surprisingly (to me) this fixed the problem. I've already digressed too 
long on this so can't look into it any more right now. Just wanted to 
put this tidbit in our archives, and see if anyone who knows more than 
I is not surprised by this, or can correct me if my analysis is 
wrong...

Jim Lyons

PS: Revolution is so cool, so fast, so powerful, to be able to do this 
kind of stuff!



More information about the use-livecode mailing list