POV-Ray : Newsgroups : povray.advanced-users : user defined function : Re: user defined function Server Time
28 Jul 2024 12:24:52 EDT (-0400)
  Re: user defined function  
From: Warp
Date: 11 Jan 2006 19:08:59
Message: <43c59e1a@news.povray.org>
Leo80s <nomail@nomail> wrote:
> I can't understand the way I could specify the value returned by a function
> (or a macro?!)...isn't there something similar a return statement?!?!

  The return value of the function is directly the evaluated expression
inside it. You don't have to "return" it explicitly.
  If you write:

#declare Func = function(A) { A*A };

then the return value of Func will be its parameter squared.

  With macros things get slightly more complicated. If you have just
a simple mathematical expression as the body of the macro, that serves
as its "return value". For example:

#macro Func(A)
  A*A
#end

  If the macro contains control flow commands, you have to use a small
trick to put a "return value". It works for example like this:

#macro Func(A)
  #if(A < 0)
    #local Result = -A;
  #else
    #local Result = A;
  #end
  A
#end

  The value of the last line of this macro is what is ultimately used as
the "substitution" of the macro call, which is practice is its "return
value".

-- 
                                                          - Warp


Post a reply to this message

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