This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
H4X0RZ's profile picture

Little question to shell.run()

Started by H4X0RZ, 20 May 2013 - 03:54 AM
H4X0RZ #1
Posted 20 May 2013 - 05:54 AM
I heared that, if you have a program (for example: test) and in this program are some lines of code. at the end you restart it with shell.run('test').

Why is this "bad"?
theoriginalbit #2
Posted 20 May 2013 - 06:04 AM
Well I guess the easiest way for me to answer is to tell you to run this program and see what happens

program name: tester

shell.run('tester')

yep thats right, stackoverflow. using shell.run at the end of your program to loop your program is recursion.
Kingdaro #3
Posted 20 May 2013 - 06:05 AM
So in other words, it's the same as doing this:

function toaster()
  toaster()
end
SuicidalSTDz #4
Posted 20 May 2013 - 07:34 AM
Reason: The stack in Lua is like a pile of clean dishes. Too many dishes and the stack crashes down. If a function yields however, it will be taken off the stack. Guess what, using recursion (in most cases) does not yield. So just don't use it if the situation you are using it in does not need it.