POV-Ray : Newsgroups : povray.general : a really dumb mistake Server Time
24 Dec 2024 20:44:45 EST (-0500)
  a really dumb mistake (Message 1 to 10 of 14)  
Goto Latest 10 Messages Next 4 Messages >>>
From: Kenneth
Subject: a really dumb mistake
Date: 2 Aug 2017 13:40:04
Message: <web.59820d705446ec0f883fb31c0@news.povray.org>
While working on my 'city buildings' scene code, I made a really simple and dumb
mistake, in a #while loop.

Consider this simplified example:

// taken from "math.inc"
#declare even = function(x) {select(mod(x, 2), 0, 1, 0)}

#declare MY_VALUE = 10;

#declare C = 1;
#while(C < 20)
#if(even(C))
#declare MY_VALUE = 33; // CHANGES the value
#else
#end
#debug concat("\n","My value = ",str(MY_VALUE,1,0),"\n")
#declare C = C + 1;
#end


EXPECTED results:  I assumed MY_VALUE would *alternate* between the new value of
33 and the old value. Wrong, of course.

ACTUAL results: After the first while-loop iteration, MY_VALUE changes to 33--
and remains at the new value. Because, once it's changed, there's nothing to
change it back to 10! It's so obvious now.

But I spent several *days* trying to track down this subtle mistake(!!)--
because, my code was so complex that I was looking for an equally complex reason
for the 'unexpected' results, having nothing to do with the #while loop at all
:-/  Like, perhaps the even() function wasn't working correctly! And half a
dozen other reasons.

No matter how smart you *think* you are, there will always be something to come
along and humble you.

But all is well now...  :-P

---------------------------------
(The proper way to do it):
#declare MY_VALUE = 10;

#declare C = 1;
#while(C < 20)
#if(even(C))
#declare MY_VALUE = 33;
#else
#declare MY_VALUE = 10;
#end
#debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
#declare C = C + 1;
#end


Post a reply to this message

From: Stephen
Subject: Re: a really dumb mistake
Date: 2 Aug 2017 14:00:15
Message: <5982132f@news.povray.org>
On 8/2/2017 6:35 PM, Kenneth wrote:
> But I spent several*days*  trying to track down this subtle mistake(!!)

The very reason I don't code. For me every line has to be debugged. ;)

-- 

Regards
     Stephen


Post a reply to this message

From: Bald Eagle
Subject: Re: a really dumb mistake
Date: 2 Aug 2017 15:10:00
Message: <web.598222ffd9dfcaaec437ac910@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

> ---------------------------------
> (The proper way to do it):
> #declare MY_VALUE = 10;
>
> #declare C = 1;
> #while(C < 20)
> #if(even(C))
> #declare MY_VALUE = 33;
> #else
> #declare MY_VALUE = 10;
> #end
> #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
> #declare C = C + 1;
> #end

(The more efficient way to do it):


 #declare C = 1;
 #while(C < 20)
 #declare MY_VALUE = 10;
    #if(even(C))
       #declare MY_VALUE = 33;
    #end
 #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
 #declare C = C + 1;
 #end



This is why I have my weird way of doing all of the debugging with that #declare
Verbose = true
so that I just plug all the debugging statements in from the start, and then
when everything works, I just switch them ALL off without any more editing.

Been there, done that, SO many times.

Glad you got your code working and regained your sanity.
Reward yourself with an adult beverage!  ;)


Post a reply to this message

From: Kenneth
Subject: Re: a really dumb mistake
Date: 2 Aug 2017 20:20:01
Message: <web.59826b23d9dfcaae883fb31c0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:

>
> (The more efficient way to do it):
>
>
>  #declare C = 1;
>  #while(C < 20)
>  #declare MY_VALUE = 10;
>     #if(even(C))
>        #declare MY_VALUE = 33;
>     #end
>  #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
>  #declare C = C + 1;
>  #end
>

Ha! I didn't see that one either. :-( :-(

Woe is me...


Post a reply to this message

From: Sven Littkowski
Subject: Re: a really dumb mistake
Date: 2 Aug 2017 22:14:32
Message: <59828708$1@news.povray.org>
On 02.08.2017 13:35, Kenneth wrote:
> While working on my 'city buildings' scene code, I made a really simple a
nd dumb
> mistake, in a #while loop.
> 
> Consider this simplified example:
> 
> // taken from "math.inc"
> #declare even = function(x) {select(mod(x, 2), 0, 1, 0)}
> 
> #declare MY_VALUE = 10;
> 
> #declare C = 1;
> #while(C < 20)
> #if(even(C))
> #declare MY_VALUE = 33; // CHANGES the value
> #else
> #end
> #debug concat("\n","My value = ",str(MY_VALUE,1,0),"\n")
> #declare C = C + 1;
> #end
> 
> 
> EXPECTED results:  I assumed MY_VALUE would *alternate* between the new v
alue of
> 33 and the old value. Wrong, of course.
> 
> ACTUAL results: After the first while-loop iteration, MY_VALUE changes to
 33--
> and remains at the new value. Because, once it's changed, there's nothing
 to
> change it back to 10! It's so obvious now.
> 
> But I spent several *days* trying to track down this subtle mistake(!!)--

> because, my code was so complex that I was looking for an equally complex
 reason
> for the 'unexpected' results, having nothing to do with the #while loop a
t all
> :-/  Like, perhaps the even() function wasn't working correctly! And half
 a
> dozen other reasons.
> 
> No matter how smart you *think* you are, there will always be something t
o come
> along and humble you.
> 
> But all is well now...  :-P
> 
> ---------------------------------
> (The proper way to do it):
> #declare MY_VALUE = 10;
> 
> #declare C = 1;
> #while(C < 20)
> #if(even(C))
> #declare MY_VALUE = 33;
> #else
> #declare MY_VALUE = 10;
> #end
> #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
> #declare C = C + 1;
> #end
> 
> 
> 
I know there someone, who uses POV-Ray since 1989 or so. And for two
weeks, this poor little fellow wondered, why his renders did not show
any expected bumps on the surface of an item. This poor little fellow
even managed to keep the POV-Ray community heavily occupied for these
two weeks with his strange problem. Over 60 postings were meade.

Finally, it turned out, that this little poor fellow forgot to chage his
QUALITY settings above 6.

I was that guy...    :-D

We all fail, at times, while at other times, POV-Ray makes us big and
making us doing great things.

---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com


Post a reply to this message

From: omniverse
Subject: Re: a really dumb mistake
Date: 2 Aug 2017 22:40:01
Message: <web.59828cc1d9dfcaae9c5d6c810@news.povray.org>
Sven Littkowski <I### [at] SvenLittkowskiname> wrote:
> On 02.08.2017 13:35, Kenneth wrote:
> >
> > No matter how smart you *think* you are, there will always be something t
> o come
> > along and humble you.
>
> We all fail, at times, while at other times, POV-Ray makes us big and
> making us doing great things.

I'm mostly humbled by POV-Ray. Just about everything is a challenge, or struggle
depending on how humbled I get!

Good going on the city macro Kenneth. And the space balloon Sven (I will
remember that mistake a very long time!).


Post a reply to this message

From: clipka
Subject: Re: a really dumb mistake
Date: 21 Aug 2017 12:01:06
Message: <599b03c2$1@news.povray.org>
Am 02.08.2017 um 21:07 schrieb Bald Eagle:
> "Kenneth" <kdw### [at] gmailcom> wrote:
> 
>> ---------------------------------
>> (The proper way to do it):
>> #declare MY_VALUE = 10;
>>
>> #declare C = 1;
>> #while(C < 20)
>> #if(even(C))
>> #declare MY_VALUE = 33;
>> #else
>> #declare MY_VALUE = 10;
>> #end
>> #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
>> #declare C = C + 1;
>> #end
> 
> (The more efficient way to do it):
> 
> 
>  #declare C = 1;
>  #while(C < 20)
>  #declare MY_VALUE = 10;
>     #if(even(C))
>        #declare MY_VALUE = 33;
>     #end
>  #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
>  #declare C = C + 1;
>  #end

Challenge accepted ;)

#declare MY_VALUE = 10;
#for(C,1,19)
  #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
  #declare MY_VALUE = 43-MY_VALUE;
#end


Post a reply to this message

From: Bald Eagle
Subject: Re: a really dumb mistake
Date: 21 Aug 2017 12:20:01
Message: <web.599b07cbd9dfcaaec437ac910@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

> Challenge accepted ;)
>
> #declare MY_VALUE = 10;
> #for(C,1,19)
>   #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
>   #declare MY_VALUE = 43-MY_VALUE;
> #end

I will have to check this out to see what it does - it looks fiendishly clever.
(someone's hogging my workbench at the moment)

(BTW - we love it when you show off.  ;) )

.... and things like this virtually scream for another POV-Ray short-code contest
..... :O


Post a reply to this message

From: Kenneth
Subject: Re: a really dumb mistake
Date: 25 Aug 2017 13:40:05
Message: <web.59a06050d9dfcaae883fb31c0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> clipka <ano### [at] anonymousorg> wrote:
>
> > Challenge accepted ;)
> >
> > #declare MY_VALUE = 10;
> > #for(C,1,19)
> >   #debug concat("\n","My Value = ",str(MY_VALUE,1,0),"\n")
> >   #declare MY_VALUE = 43-MY_VALUE;
> > #end
>
> I will have to check this out to see what it does...
>

Same here! At first appearance, it doesn't seem like it would work at all. But
it DOES work! Yes, devilishly clever.

Hmm, let's see...

1) MY_VALUE starts at 10
2) 1st #debug = 10
3) MY_VALUE changes to (43 - 10) = 33
4) 2nd #debug = 33
5) MY_VALUE changes to (43 - 33) = 10
6) 3rd #debug = 10
7) MY_VALUE changes to (43 - 10) = 33
8) 4th #debug = 33

....ETC...

Magical!


Post a reply to this message

From: Kenneth
Subject: Re: a really dumb mistake
Date: 25 Aug 2017 13:50:06
Message: <web.59a0629fd9dfcaae883fb31c0@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

>
> Magical!
>

In the 16th century, the Inquisition would have burned Clipka at the stake, as a
warning to other such Necromancers :-P


Post a reply to this message

Goto Latest 10 Messages Next 4 Messages >>>

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