POV-Ray : Newsgroups : povray.general : #macros-- a simple question Server Time
28 Mar 2024 09:22:45 EDT (-0400)
  #macros-- a simple question (Message 1 to 4 of 4)  
From: Kenneth
Subject: #macros-- a simple question
Date: 8 Jul 2017 16:25:00
Message: <web.59613eb1a944d1b4883fb31c0@news.povray.org>
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(!)

Did v3.6xx operate differently?

*** By the way, the in-built documentation about macros says only this: "A macro
must be declared before it is invoked."  Hmm. Depending on how I read that, it
could mean the *obvious* fact that something-- anything-- needs to be created
before it can be used. OR, it could mean that the #macro definition needs to be
WRITTEN earlier in the scene file first, to be FOLLOWED by the invocation of it
later (like any other linear-programming item.) The wording is a wee bit too
simplistic and ambiguous.


Post a reply to this message

From: Simon J  Cambridge
Subject: Re: #macros-- a simple question
Date: 8 Jul 2017 17:25:00
Message: <web.59614d261c20efa621bb12460@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:
> 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(!)
>
> Did v3.6xx operate differently?
>
> *** By the way, the in-built documentation about macros says only this: "A macro
> must be declared before it is invoked."  Hmm. Depending on how I read that, it
> could mean the *obvious* fact that something-- anything-- needs to be created
> before it can be used. OR, it could mean that the #macro definition needs to be
> WRITTEN earlier in the scene file first, to be FOLLOWED by the invocation of it
> later (like any other linear-programming item.) The wording is a wee bit too
> simplistic and ambiguous.

I just tried this in 3.62 and it must be linear, macro first (higher up), then
its invocation, lower down.

As soon as I saw your question it made wonder...

Cheers,

Simon.


Post a reply to this message

From: clipka
Subject: Re: #macros-- a simple question
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

From: Kenneth
Subject: Re: #macros-- a simple question
Date: 9 Jul 2017 14:55:00
Message: <web.59627b4d1c20efa6883fb31c0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
>
Thanks to you both, for clearing this up (and for testing it in 3.62.)
>
> 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
>
The above should be included in the documentation, IMO. It clarifies the basics
of how to write a macro and its call.

> 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.
>
Yes, perfectly clear now. (Perhaps *that* kind of example is what I was thinking
of, from the past(?))

Here's the strange part of all this, personally speaking: I can almost visualize
writing a scene file years ago where *something* in the code did not have to be
written in a typical 'linear' way. (I thought for sure that it was a macro-- but
what else it could have been, I have no clue.) The memory of it is quite
clear(!)... (well, it's obviously a *faulty* memory...)


Post a reply to this message

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