|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Hello,
A little stuck here... evidently povray does not support any type of
Return() function, and I am not familiar enough with sdl yet to figure this
out any other way.
This little macro does what it says, but not in this form.
#macro isEvenOrOdd(integer)
#if(mod(integer,2) = 0)
#local isEven = 1;
#else
#local isOdd = 1;
#end
#end
I had to use an instance of the following each time that I wished to use
this function:
// Determines if even or odd
#if(mod(glowTypeRand,2) = 0)
type 0
#else
type 2
#end
There HAS to be some way to pass variables from a macro...right? :-\
Thanks,
Ian
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Wasn't it [GDS|Entropy] who wrote:
>Hello,
>
>A little stuck here... evidently povray does not support any type of
>Return() function, and I am not familiar enough with sdl yet to figure this
>out any other way.
>This little macro does what it says, but not in this form.
>
>#macro isEvenOrOdd(integer)
> #if(mod(integer,2) = 0)
> #local isEven = 1;
> #else
> #local isOdd = 1;
> #end
>#end
>
>There HAS to be some way to pass variables from a macro...right? :-\
You're confusing the concept of MACRO with the concept of FUNCTION.
The entire contents of a macro are "returned", so you can write:
#macro isEven(integer)
#if(mod(integer,2) = 0)
#local even = 1;
#else
#local even = 0;
#end
(even)
#end
#if (isEven(3))
#debug "3 is even\n"
#else
#debug "3 is odd\n"
#end
Or
#macro isOdd(integer)
(mod(integer,2))
#end
#if (isOdd(3))
#debug "3 is odd\n"
#else
#debug "3 is even\n"
#end
Don't get confused into thinking that those macros get evaluated and
then return integer values. They "return" chunks of SDL code like
#if(mod(3,2) = 0) #local even=1; #else #local even = 0; #end (even)
And what happens is that
#if (isEven(3))
effectively becomes
#if (#if(mod(3,2) = 0) #local even=1; #else #local even = 0; #end
(even))
and THEN gets evaluated.
--
Mike Williams
Gentleman of Leisure
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Ahh...I think I see now.
So essentially a macro in pov-sdl, when called, returns a code
block/whatever its contents happen to be?
Am I correct to believe they can be written to represent so-called
"high-order" functions, which will accept a functions as a variable, and can
return other functions as a result?
If this is the case, it will now be much easier to work with macros, as
before I was treating them as low-level functions.
I guess that debug/concat feature might help in determining this sort of
thing in the future, huh? hehehe :-)
Thanks,
Ian
"Mike Williams" <nos### [at] econymdemoncouk> wrote in message
news:gc5### [at] econymdemoncouk...
> Wasn't it [GDS|Entropy] who wrote:
>>Hello,
>>
>>A little stuck here... evidently povray does not support any type of
>>Return() function, and I am not familiar enough with sdl yet to figure
>>this
>>out any other way.
>>This little macro does what it says, but not in this form.
>>
>>#macro isEvenOrOdd(integer)
>> #if(mod(integer,2) = 0)
>> #local isEven = 1;
>> #else
>> #local isOdd = 1;
>> #end
>>#end
> >
>>There HAS to be some way to pass variables from a macro...right? :-\
>
> You're confusing the concept of MACRO with the concept of FUNCTION.
>
> The entire contents of a macro are "returned", so you can write:
>
>
> #macro isEven(integer)
> #if(mod(integer,2) = 0)
> #local even = 1;
> #else
> #local even = 0;
> #end
> (even)
> #end
>
> #if (isEven(3))
> #debug "3 is even\n"
> #else
> #debug "3 is odd\n"
> #end
>
>
> Or
> #macro isOdd(integer)
> (mod(integer,2))
> #end
>
> #if (isOdd(3))
> #debug "3 is odd\n"
> #else
> #debug "3 is even\n"
> #end
>
>
> Don't get confused into thinking that those macros get evaluated and then
> return integer values. They "return" chunks of SDL code like
> #if(mod(3,2) = 0) #local even=1; #else #local even = 0; #end (even)
> And what happens is that
> #if (isEven(3))
> effectively becomes
> #if (#if(mod(3,2) = 0) #local even=1; #else #local even = 0; #end
> (even))
> and THEN gets evaluated.
>
> --
> Mike Williams
> Gentleman of Leisure
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"[GDS|Entropy]" <gds### [at] hotmailcom> wrote:
> So essentially a macro in pov-sdl, when called, returns a code
> block/whatever its contents happen to be?
it doesn't "return" anything: it textually copies it contents with parameters
substituted for real values.
> Am I correct to believe they can be written to represent so-called
> "high-order" functions, which will accept a functions as a variable, and can
> return other functions as a result?
it's not really like Lisp macros, more akin to C "macros"
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
nemesis <nam### [at] gmailcom> wrote:
> "[GDS|Entropy]" <gds### [at] hotmailcom> wrote:
> > So essentially a macro in pov-sdl, when called, returns a code
> > block/whatever its contents happen to be?
> it doesn't "return" anything: it textually copies it contents with parameters
> substituted for real values.
Not really. POV-Ray doesn't copy anything. When a macro call is encountered
it jumps to the macro body and continues parsing there. When the macro has
been parsed, it returns to the origin of the jump.
The difference can be seen eg. with #locals.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp <war### [at] tagpovrayorg> wrote:
> nemesis <nam### [at] gmailcom> wrote:
> > "[GDS|Entropy]" <gds### [at] hotmailcom> wrote:
> > > So essentially a macro in pov-sdl, when called, returns a code
> > > block/whatever its contents happen to be?
>
> > it doesn't "return" anything: it textually copies it contents with parameters
> > substituted for real values.
>
> Not really. POV-Ray doesn't copy anything. When a macro call is encountered
> it jumps to the macro body and continues parsing there. When the macro has
> been parsed, it returns to the origin of the jump.
>
> The difference can be seen eg. with #locals.
hmm, less bad...
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Remember that #local and #declare are not the same
scope. #local inside a macro is local to the macro,
but a #declare inside a macro is global. If you
use #declare inside a macro you can use the
declared variable to return values.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Warp" <war### [at] tagpovrayorg> schreef in bericht
news:479c2f65@news.povray.org...
>
> Not really. POV-Ray doesn't copy anything. When a macro call is
> encountered
> it jumps to the macro body and continues parsing there. When the macro has
> been parsed, it returns to the origin of the jump.
>
...reminds me of the good old 'subroutines' in Fortran...
Thomas
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Thomas de Groot wrote:
> "Warp" <war### [at] tagpovrayorg> schreef in bericht
> news:479c2f65@news.povray.org...
>> Not really. POV-Ray doesn't copy anything. When a macro call is
>> encountered
>> it jumps to the macro body and continues parsing there. When the macro has
>> been parsed, it returns to the origin of the jump.
>>
>
> ....reminds me of the good old 'subroutines' in Fortran...
Nah. Fortran just didn't guarantee you had a stack on the machine. And
many mainframes of the time didn't. You had "BAL" - Branch And Link,
which left the previous program counter in a register and branched to
the new address. Actually pushing that register onto a stack after was
usually-unnecessary overhead.
--
Darren New / San Diego, CA, USA (PST)
On what day did God create the body thetans?
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |