POV-Ray : Newsgroups : povray.bugreports : alpha.10064268 macro problem : Re: alpha.10064268 macro problem Server Time
20 Apr 2024 05:13:06 EDT (-0400)
  Re: alpha.10064268 macro problem  
From: clipka
Date: 29 May 2021 15:25:19
Message: <60b2951f$1@news.povray.org>
Am 04.04.2021 um 19:48 schrieb Bald Eagle:
> Instead of a boolean, return an integer flag to be further processed.
> (POV-Ray treats any non-zero value as "true")
> Then you can initially process the result as a boolean like you do, but then
> have a follow-up procedure that instantiates the sphere, maybe using #select.
> 
> Or maybe you can just do that with the simple "boolean" as well...

Just skimming the thread, but from what I'm gathering, it seems that the 
crux of the matter is that there's some construct where a macro would 
essentially have to emit ("return") _two_ values separately: A status 
result (boolean, apparently) that would have to be plonked into an 
`#if(BOOLEAN)`, and an object that would have to be plonked elsewhere.

Fun fact: Unless my memory has been badly scrambled in the days of my 
abscence, modern POV-Ray v3.8 can do such exciting stuff, using 
tuple-style assignments, like so:

     #declare (Foo,Bar) = (VALUE1,VALUE2);

This allows you to design a macro that is structured like so (and as a 
matter of fact the syntax was introduced for exactly this very purpose):

     #macro Frobnitz()
         // Construct the stuff we want to emit ("return")
         #local V1 = ...;
         #local V2 = ...;
         // Actually emit ("return") the stuff, tuple-style
         (V1,V2)
     #end

And then invoke it from some other code like so:

     #declare (Foo,Bar) = Frobnitz();
     // test for `Foo`
     #if(Foo)
         // emit `Bar` to actually plonk it into the scene
         object { Bar }
     #end

Hope this helps.

Oh, and in case you have a macro that may not have an object to emit as 
the second value, try this (IIRC think it should work):

     #macro Frobnitz()
         #if(GOOD)
           #local V2 = ...;
           (true,V2)
         #else
           (false,)
         #end
     #end

And then invoke it from some other code like so:

     #declare Bar = sphere { ... } // provide default for Bar
     #declare (Foo, optional Bar) = Frobnitz();
     // test for `Foo`
     #if(Foo)
         // emit `Bar` to actually plonk it into the scene
         object { Bar }
     #end

(I'm not 100% sure I recall the `optional` semantics properly; IIRC it 
leaves the variable unchanged if no value is given, but it might also 
set it to undefined instead. Also, I'm not 100% the comma in `(false,)` 
is necessary or not. It's docomented... somewhere.)


Oh, and of course array- and vector-style assignments were also 
introduced on that occasion, just for funsies:

     #declare A = array[2] {VALUE1,VALUE2};
     #declare [Foo,Bar] = A; //(*)

     #declare V = <VALUE1,VALUE2>;
     #declare <Foo,Bar> = V;

(*) I _think_ that was the syntax. Mighth have been curly braces instead 
of square brackets though, i.e `#declare {Foo,Bar} = A;`. Again, it's 
documented... somewhere.


Post a reply to this message

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