POV-Ray : Newsgroups : povray.general : #macros-- a simple question : Re: #macros-- a simple question Server Time
28 Apr 2024 17:50:28 EDT (-0400)
  Re: #macros-- a simple question  
From: clipka
Date: 8 Jul 2017 17:57:16
Message: <5961553c$1@news.povray.org>
Am 08.07.2017 um 22:21 schrieb Kenneth:
> This little problem makes me feel like I'm losing more brain cells than normal,
> as I get older. But I'll explain anyway...
> 
> From my (faulty??) memory of POV-Ray v3.6xx days, I thought that a #macro could
> be written *anywhere* in a scene file, and called from anywhere. In other words,
> no need to write the two in a 'linear' way in the file-- #macro first, THEN the
> call. But I now see that in 3.7xx (3.7.1 beta 8), a #macro needs to be written
> 'higher up' in the file, before it's called later in the scene. (Doing the
> reverse doesn't work.) For some strange reason, this comes as a surprise to
> me(!)

A macro must always be defined before it is /actually/ invoked. So the
following will /not/ work:

    Foo()
    #macro Foo()
      #debug "in Foo\n"
    #end

Note that it's the time of definition and invocation that matters, not
the location within the code. So the following example is perfectly fine:

    #macro Bar()
      Foo()
    #end
    #macro Foo()
      #debug "in Foo\n"
    #end
    Bar()

Here, the call to `Foo()` is placed before the definition, but it's not
actually invoked there; instead, that invocation is delayed until
`Bar()` is invoked, which happens after `Foo()` is already defined.

> Did v3.6xx operate differently?

No, this has always been the way macros worked in POV-Ray.

There are interpreted languages where subroutines do not have to be made
known in advance (e.g. Windows `cmd.exe` batch files), but POV-Ray has
never been one of them.


Post a reply to this message

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