POV-Ray : Newsgroups : povray.beta-test : Optional macro parameters Server Time
22 Dec 2024 09:02:27 EST (-0500)
  Optional macro parameters (Message 1 to 7 of 7)  
From: Bald Eagle
Subject: Optional macro parameters
Date: 23 Mar 2017 12:05:00
Message: <web.58d3f1da55c5eb5fc437ac910@news.povray.org>
I tried to write a macro using optional parameters.

POV-Ray gave me back errors, saying it wanted n parameters, but I only supplied
x.

The number of parameters I specified was n, ranging from 0 to 4.
I tried supplying 0-3, but it seemed to want all 4.

That was with beta 2.

I will supply more info if necessary.
Has anyone else tried running an optional parameter macro?

Can someone post sample code?


Post a reply to this message

From: Le Forgeron
Subject: Re: Optional macro parameters
Date: 23 Mar 2017 14:36:30
Message: <58d415ae$1@news.povray.org>
Le 23/03/2017 à 17:03, Bald Eagle a écrit :
> I tried to write a macro using optional parameters.
> 
> POV-Ray gave me back errors, saying it wanted n parameters, but I only supplied
> x.
> 
> The number of parameters I specified was n, ranging from 0 to 4.
> I tried supplying 0-3, but it seemed to want all 4.
> 
> That was with beta 2.
> 
> I will supply more info if necessary.
> Has anyone else tried running an optional parameter macro?
> 
> Can someone post sample code?
> 

Could provide the code you tried first ?

My guess so far is : #version...


Post a reply to this message

From: clipka
Subject: Re: Optional macro parameters
Date: 23 Mar 2017 15:10:21
Message: <58d41d9d$1@news.povray.org>
Am 23.03.2017 um 17:03 schrieb Bald Eagle:
> I tried to write a macro using optional parameters.
> 
> POV-Ray gave me back errors, saying it wanted n parameters, but I only supplied
> x.
> 
> The number of parameters I specified was n, ranging from 0 to 4.
> I tried supplying 0-3, but it seemed to want all 4.

You can omit the optional parameters, but you still have to specify the
commas. For example:

    #macro Foo(A, optional B, C)
      ...
    #end

    Foo(1,,3)

Currently, this is true even if the optional parameters are at the end
of the parameter list:

    #macro Foo(A, B, optional C)
      ...
    #end

    Foo(1,2,)


Post a reply to this message

From: Mike Horvath
Subject: Re: Optional macro parameters
Date: 23 Mar 2017 16:08:45
Message: <58d42b4d$1@news.povray.org>
On 3/23/2017 3:10 PM, clipka wrote:
> Am 23.03.2017 um 17:03 schrieb Bald Eagle:
>> I tried to write a macro using optional parameters.
>>
>> POV-Ray gave me back errors, saying it wanted n parameters, but I only supplied
>> x.
>>
>> The number of parameters I specified was n, ranging from 0 to 4.
>> I tried supplying 0-3, but it seemed to want all 4.
>
> You can omit the optional parameters, but you still have to specify the
> commas. For example:
>
>     #macro Foo(A, optional B, C)
>       ...
>     #end
>
>     Foo(1,,3)
>
> Currently, this is true even if the optional parameters are at the end
> of the parameter list:
>
>     #macro Foo(A, B, optional C)
>       ...
>     #end
>
>     Foo(1,2,)
>

That is some weird syntax.


Mike


Post a reply to this message

From: dick balaska
Subject: Re: Optional macro parameters
Date: 24 Mar 2017 02:10:14
Message: <58d4b846@news.povray.org>
Am 2017-03-23 16:09, also sprach Mike Horvath:

> That is some weird syntax.

Indeed.

Although not *completely* unheard of. A C for statement could look 
similarly.
   int i=0;
   for (;;i++)
       if (i>10)
           break;

I may have gone with "C = -1" instead of "optional C"
I see mysterious namespace collisions in your future.
-- 
dik


Post a reply to this message

From: Bald Eagle
Subject: Re: Optional macro parameters
Date: 24 Mar 2017 07:35:01
Message: <web.58d503f6af5861a3c437ac910@news.povray.org>
#macro Test (optional A, optional B, optional C, optional D)
 #debug "Start macro Test \n"
 #ifndef (local.A)
  #debug "No parameters defined \n"
 #end

 #ifdef (local.A)
  #macro _Test (A, B, optional C, optional D)

  #end // end macro _Test
 #end
 #debug "End macro Test \n"
#end // end macro Test


With Test (1, 2) I get "expected 4 but only found 2", or

with Test (1, 2)
"expected 8 but only found 2"


Post a reply to this message

From: clipka
Subject: Re: Optional macro parameters
Date: 24 Mar 2017 17:12:34
Message: <58d58bc2$1@news.povray.org>
Am 24.03.2017 um 12:33 schrieb Bald Eagle:
> #macro Test (optional A, optional B, optional C, optional D)
>  #debug "Start macro Test \n"
>  #ifndef (local.A)
>   #debug "No parameters defined \n"
>  #end

That test isn't really accurate. `#ifndef(local.A)` only tells you
whether the first parameter was omitted; parameters B, C and/or D might
still be supplied, as in:

    Test(,2,3,4)

Note that POV-Ray's optinal parameters differ from those in C/C++ in
that you can declare _any_ parameter as optional, not just the last
ones. For example, in

    #macro Test(optional A, B, C, D)
    #end

only parameter A is optional, the others are mandatory.

Also, POV-Ray allows you to pass undefined variables to optional
parameters, e.g.:

    #undef Blah
    Test(Blah,2,3,4)


>  #ifdef (local.A)
>   #macro _Test (A, B, optional C, optional D)
> 
>   #end // end macro _Test
>  #end
>  #debug "End macro Test \n"
> #end // end macro Test

Defining a macro inside a macro? That's... uh... yeah, /possible/, I guess.


> With Test (1, 2) I get "expected 4 but only found 2", or
> 
> with Test (1, 2)
> "expected 8 but only found 2"

That statement of yours doesn't make sense.


Post a reply to this message

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