POV-Ray : Newsgroups : povray.pov4.discussion.general : I want to be rid of my stupid mistakes : Re: I want to be rid of my stupid mistakes Server Time
6 May 2024 09:47:45 EDT (-0400)
  Re: I want to be rid of my stupid mistakes  
From: Nicolas Alvarez
Date: 20 Aug 2009 02:52:47
Message: <4a8cf2bf@news.povray.org>
clipka wrote:

> "scott" <sco### [at] scottcom> wrote:
>> I'm not saying it's possible to detect whether any program will stop or
>> not. I'm saying that in *some* cases you can relatively easily detect
>> that it won't stop without changing the functionality.
> 
> I'm definitely repeating myself here: Those easy cases would come packaged
> with too many not-so-easy special cases.
> 
> Sure you can detect a simple
> 
>   #while (i < N)
>     //#declare i=...
>   #end
> 
> as being an infinite loop, but that's an absolutely trivial case; as soon
> as you go from there to
> 
>   #while (i < N)
>     ...
>     //#declare i=...
>     ...
>   #end
> 
> then if you don't find a "#declare i=...", you *must* examine the "..."
> thoroughly before you can conclude that the user really forgot it.
> 
> Of course, if you *do* find a "#declare i=..." in there, you can tell for
> sure the user did *not* forget it; but that doesn't get us any further.
> 
> The bottom line is that a potentially-infite-loop detector would be a
> quite complex piece of code, even if it were just to catch some standard
> cases. There would be much easier and more useful remedies for the
> forgotten-increment ailment.

I think most of the cases previously posted here are actually solvable. That
is, you can avoid thinking it's infinite when it's not (you can't avoid the
opposite, but it's OK, we don't have to detect all cases, and it's
impossible anyway). I have yet to see someone post a convincing code
snippet that would give a false positive.

#declare I=0;
#while (I < Limit)
   //...
#end

If neither 'I' nor 'Limit' are ever mentioned inside the loop, it's
infinite. Otherwise, it may be infinite, but assume it's not and let it
run.

#declare I=0;
#while (I < Limit)
    //...
    #include "file.inc"
#end

Just assume it's not infinite if there is an include, since it's prone to
way too many variables. For example, the user could edit file.inc in the
middle of the parsing to have #declare I=Limit;


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.