[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How to avoid "infinite loop"
- From: Sean Conner <sean@...>
- Date: Wed, 2 Sep 2015 17:03:52 -0400
It was thus said that the Great Elias Barrionovo once stated:
> On Wed, Sep 2, 2015 at 5:36 PM, Rodrigo Azevedo <email@example.com> wrote:
> > Is Lua a "infinite loop" safe language in any conception? (I really don't
> > know the strategies involved to check/avoid these cases at implementation
> > level)
> Alan Turing famously proved that there is no general way  of
> finding out whether a piece of program terminates for an arbitrary
> input without actually running it and hoping for the best. It's known
> as the Halting Problem: https://en.wikipedia.org/wiki/Halting_problem
> However, there are certain heuristics. For instance, you could create
> a graph of branches and function calls and see if there are any
> cycles, but it is very error prone (add some basic metatable or ENV
> trickery and the checker won't work).
> Usually, what is done is to limit the total runtime of a piece of
> code, which in Lua can be done using hooks and the debug library.
> Others in this list may enlight you in this matter.
This is probably the best way, as there are other ways to fall into an
for i = 1 , 1 , 0 do end
while true do end
repeat until false
function a() return a() end a()
-spc (Recursion: see recursion)