I am converting a spreadsheet into ruby so that it may be executed as part
of a bigger system. This has worked well for sheets with only 1,000s of
cells. There is a problem with sheets that have nearly 200,000 cells. The
program blows up when it runs.
Here is a simplified example:
def zxc(value)
x0 = value
x1 = x0 + 1
x2 = x1 + 1
x3 = x2 + 1
x4 = x3 + 1
x5 = x4 + 1
x6 = x5 + 1
x7 = x6 + 1
x8 = x7 + 1
# More of the same until...
x99995 = x99994 + 1
x99996 = x99995 + 1
x99997 = x99996 + 1
x99998 = x99997 + 1
x99999 = x99998 + 1
x100000 = x99999 + 1
return x100000
end
puts zxc(0)
This will run without error and returns 100000 as expected. But if the code
gets larger, such as:
x149995 = x149994 + 1
x149996 = x149995 + 1
x149997 = x149996 + 1
x149998 = x149997 + 1
x149999 = x149998 + 1
x150000 = x149999 + 1
return x150000
end
puts zxc(0)
The result is:
x2.rb:150006:in `<main>': stack level too deep (SystemStackError)
The program is linear and does not iterate or recurse. Is there a way round
this limit?