POV-Ray : Newsgroups : povray.general : Error - missing semicolon when using macro Server Time
9 Oct 2024 01:59:44 EDT (-0400)
  Error - missing semicolon when using macro (Message 1 to 6 of 6)  
From: Tom A 
Subject: Error - missing semicolon when using macro
Date: 21 Jan 2023 13:20:00
Message: <web.63cc2badcc2a7a8c1742c61c57ffd389@news.povray.org>
Error with #local and #macro (?)

I have a macro to turn a part of time into it's own 0-1 value.
(Useful for running landing geer and doors that take time to go from not open to
open or deployed).

Here is some test code:

 // problem test
 #version 3.7;

 #macro subclock2( start, complete, cnt)
   // converts time (in cnt) between start and complete into
   // a value between 0 and 1

   #if (cnt< start)
  0
   #else
  #if (cnt>complete)
    1
  #else
    ((cnt - start) / (complete - start))
  #end
   #end
 #end // subclock2

 #local cccc = clock;

 #local c2 = subclock2(.1,.2,cccc);


However, when I use it, I get

"C:\POVRay\scenes\ArtDecoShips\errortest.pov" line 11: Parse Error: All
#declares of float, vector, and color require semi-colon ';' at
end if the language version is set to 3.5 or higher. Either add the semi-colon
or set the language version to 3.1 or lower.

Render failed
-

Yet the actual line where the macro is invoked has a semicolon.

The code can be made to work by putting parentheses around the call:
#local c2 = ( subclock2(.1,.2,cccc) );

This took me a long time to solve (I hate the error messages - points to the
macro line, leaving me trying to figure out which call generated the error.)

Did I miss something in the help text?

Tom A.


Post a reply to this message

From: Cousin Ricky
Subject: Re: Error - missing semicolon when using macro
Date: 21 Jan 2023 16:15:31
Message: <63cc55f3$1@news.povray.org>
On 2023-01-21 14:15 (-4), Tom A. wrote:
> 
> However, when I use it, I get
> 
> "C:\POVRay\scenes\ArtDecoShips\errortest.pov" line 11: Parse Error: All
> #declares of float, vector, and color require semi-colon ';' at
> end if the language version is set to 3.5 or higher. Either add the semi-colon
> or set the language version to 3.1 or lower.
> 
> Render failed
> -
> 
> Yet the actual line where the macro is invoked has a semicolon.
> 
> The code can be made to work by putting parentheses around the call:
> #local c2 = ( subclock2(.1,.2,cccc) );

If you put the parentheses around the body of the macro, you won't have
to babysit the macro with each call:

 #macro subclock2( start, complete, cnt)
   // converts time (in cnt) between start and complete into
   // a value between 0 and 1
 (
   #if (cnt< start)
  0
   #else
  #if (cnt>complete)
    1
  #else
    ((cnt - start) / (complete - start))
  #end
   #end
 )
 #end // subclock2


Post a reply to this message

From: Bald Eagle
Subject: Re: Error - missing semicolon when using macro
Date: 21 Jan 2023 16:35:00
Message: <web.63cc597f6284db5a1f9dae3025979125@news.povray.org>
"Tom A." <met### [at] yahoocom> wrote:
> Error with #local and #macro (?)
>
> I have a macro to turn a part of time into it's own 0-1 value.
> (Useful for running landing geer and doors that take time to go from not open to
> open or deployed).
>
> Here is some test code:
>
>  // problem test
>  #version 3.7;
>
>  #macro subclock2( start, complete, cnt)
>    // converts time (in cnt) between start and complete into
>    // a value between 0 and 1
>
>    #if (cnt< start)
>   0
>    #else
>   #if (cnt>complete)
>     1
>   #else
>     ((cnt - start) / (complete - start))
>   #end
>    #end
>  #end // subclock2
>
>  #local cccc = clock;
>
>  #local c2 = subclock2(.1,.2,cccc);
>
>
> However, when I use it, I get
>
> "C:\POVRay\scenes\ArtDecoShips\errortest.pov" line 11: Parse Error: All
> #declares of float, vector, and color require semi-colon ';' at
> end if the language version is set to 3.5 or higher. Either add the semi-colon
> or set the language version to 3.1 or lower.
>
> Render failed
> -
>
> Yet the actual line where the macro is invoked has a semicolon.
>
> The code can be made to work by putting parentheses around the call:
> #local c2 = ( subclock2(.1,.2,cccc) );
>
> This took me a long time to solve (I hate the error messages - points to the
> macro line, leaving me trying to figure out which call generated the error.)
>
> Did I miss something in the help text?
>
> Tom A.


Well, this is something people run into a lot.
It's a little hard to divine where in the parser it's coming across something it
doesn't like.

Why don't you scrap most of it and use min, max, and your formula, thus
eliminating most of the code.
I'd also let the macro grab the clock value when it's invoked, saving you from
doing that every time before invoking the macro.

Then I'd store your subclock2 value in a variable, and then export that variable
name from the macro, so that everything is nice and neat and tidy - and
therefore easier to debug.

// converts time (in cnt) between start and complete into
// a value between 0 and 1
// (Keeping comments outside of macro saves a small amount of code parsing
//     and speeds things up depending on the number of macro calls)
#macro Subclock2 (Start, End)
 #local CurrentClock = clock;
 #local NormalizedClock = min (max ( ((CurrentClock - Start) / (End - Start)),
1), 0);

 NormalizedClock

#end // subclock2


Now you just invoke it like so:

#local c2 = Subclock2 (0.1, 0.2);


Post a reply to this message

From: Bald Eagle
Subject: Re: Error - missing semicolon when using macro
Date: 21 Jan 2023 16:40:00
Message: <web.63cc5ac36284db5a1f9dae3025979125@news.povray.org>
Sorry - I always switch the min and max.

// converts time (in cnt) between start and complete into
// a value between 0 and 1
// (Keeping comments outside of macro saves a small amount of code parsing
//     and speeds things up depending on the number of macro calls)
#macro Subclock2 (Start, End)
 #local CurrentClock = clock;
 #local NormalizedClock = min (max ( ((CurrentClock - Start) / (End - Start)),
0), 1);

 NormalizedClock

#end // subclock2


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Error - missing semicolon when using macro
Date: 21 Jan 2023 17:20:00
Message: <web.63cc63d76284db5a892957989db30a9@news.povray.org>
"Tom A." <met### [at] yahoocom> wrote:
> Error with #local and #macro (?)
>
> I have a macro to turn a part of time into it's own 0-1 value.
> (Useful for running landing geer and doors that take time to go from not open to
> open or deployed).
>
> Here is some test code:
>
>  // problem test
>  #version 3.7;
>
>  #macro subclock2( start, complete, cnt)
>    // converts time (in cnt) between start and complete into
>    // a value between 0 and 1
>
>    #if (cnt< start)
>   0
>    #else
>   #if (cnt>complete)
>     1
>   #else
>     ((cnt - start) / (complete - start))
>   #end
>    #end
>  #end // subclock2
>
>  #local cccc = clock;
>
>  #local c2 = subclock2(.1,.2,cccc);
>
>
> However, when I use it, I get
>
> "C:\POVRay\scenes\ArtDecoShips\errortest.pov" line 11: Parse Error: All
> #declares of float, vector, and color require semi-colon ';' at
> end if the language version is set to 3.5 or higher. Either add the semi-colon
> or set the language version to 3.1 or lower.
>
> Render failed
> -
>
> Yet the actual line where the macro is invoked has a semicolon.
>
> The code can be made to work by putting parentheses around the call:
> #local c2 = ( subclock2(.1,.2,cccc) );
>
> This took me a long time to solve (I hate the error messages - points to the
> macro line, leaving me trying to figure out which call generated the error.)
>
> Did I miss something in the help text?

Hi Tom

I would recommend that you go for the min(max()) solution that Bill just
suggested.

But in the future; if you want to write macros similar to you the one you
posted, I suggest that you write them like this:


#macro Subclock2(Start, Complete, Cnt)

    #if (Cnt <  Start)
        #local Time = 0;
    #else
        #if (Cnt > Complete)
            #local Time = 1;
        #else
            #local Time = ((Cnt - Start)/(Complete - Start));
        #end // if
    #end // if

    Time

#end // macro Subclock2


I.e. return the value of a local variable at the end of the macro.

This will increase the readability of your code, make it easier to debug and
take care of the semicolon problem you experienced.

Here's my take on the min(max()) variant:


#macro Subclock2(Start, Complete, Cnt)

    min(max(0, (Cnt - Start)/(Complete - Start)), 1)

#end // macro Subclock2


Returning a single expression is also ok in my opinion. But beware: Some
expressions should be enclosed in parentheses. Eg. like this: (A + B)

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: Tom A 
Subject: Re: Error - missing semicolon when using macro
Date: 21 Jan 2023 23:50:00
Message: <web.63ccbfff6284db5a1742c61c57ffd389@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:

>
> Here's my take on the min(max()) variant:
>
>
> #macro Subclock2(Start, Complete, Cnt)
>
>     min(max(0, (Cnt - Start)/(Complete - Start)), 1)
>
> #end // macro Subclock2
>

Thanks all.  And I do like that min-max solution.

Tom A.


Post a reply to this message

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