POV-Ray : Newsgroups : povray.newusers : Returning values from macros Server Time
7 May 2024 09:09:35 EDT (-0400)
  Returning values from macros (Message 21 to 24 of 24)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: dick balaska
Subject: Re: Returning values from macros
Date: 2 Jun 2016 21:51:42
Message: <5750e2ae$1@news.povray.org>
Am 2016-06-02 21:37, also sprach Bald Eagle:
> With respect to scope,
>
> I have a variable that I declare locally:
>
> #local Steps = ....
>
> I tried to:
>
> #declare Steps = Steps;
>
> and then use Steps outside of the macro - "undeclared identifier"   :(
>
> I can't "hand-off" a local value to a global identifier of the same name?
> or "redefine a local variable as a global variable" ?

Anti-patterns are apparently not supported in this case.


-- 
dik


Post a reply to this message

From: clipka
Subject: Re: Returning values from macros
Date: 3 Jun 2016 08:27:50
Message: <575177c6$1@news.povray.org>
Am 03.06.2016 um 03:37 schrieb Bald Eagle:
> With respect to scope,
> 
> I have a variable that I declare locally:
> 
> #local Steps = ....
> 
> I tried to:
> 
> #declare Steps = Steps;
> 
> and then use Steps outside of the macro - "undeclared identifier"   :(
> 
> I can't "hand-off" a local value to a global identifier of the same name?
> or "redefine a local variable as a global variable" ?

POV-Ray 3.7 indeed provides no way to assign a value to a global
variable if there already exists a variable with the same name at any
"more local" scope.

However, POV-Ray 3.7.1 will introduce a mechanism to specifically access
identifiers at the global scope, allowing you to achieve the desired
effect using the following syntax:

    #declare global(Steps) = Steps;

The `global(IDENTIFIER)` pseudo-function will be available wherever the
"bare" identifier could be used, and will cause any local identifiers of
the same name to be ignored when resolving the identifier.

There will also be a corresponding `local(IDENTIFIER)` pseudo-function
to specifically access identifiers at the "most local" scope, causing
identifiers at any "less local" scope to be ignored.

This functionality is already available in the current development releases.


Post a reply to this message

From: Bald Eagle
Subject: Re: Returning values from macros
Date: 3 Jun 2016 12:45:00
Message: <web.5751b3e076b80bcdb488d9aa0@news.povray.org>
So, I just finished hunting down an old post by Jaap Frank about working around
the official limitation on datan types in arrays.

Just thought I'd repost the link as a reminder, since that was 13 years ago.  :)

http://news.povray.org/povray.text.tutorials/thread/%3C3f13449b$1@news.povray.org%3E/


Post a reply to this message

From: JimT
Subject: Re: Returning values from macros
Date: 3 Jun 2016 15:50:00
Message: <web.5751decd76b80bcda4b712a50@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> So, I just finished hunting down an old post by Jaap Frank about working around
> the official limitation on datan types in arrays.
>
> Just thought I'd repost the link as a reminder, since that was 13 years ago.  :)
>
>
http://news.povray.org/povray.text.tutorials/thread/%3C3f13449b$1@news.povray.org%3E/

I hesitate to try to add to what clipka says but...

If you #declare anything in a #macro, it is a global variable and will be known
outside the #macro and will assign a value to that variable name outside the
#macro, which is, of course usually a bad idea. Defining and assigning values to
local variables inside a #macro is what #local is for.

You can use #local to re-assign values to #macro arguments, even though they
must already have been defined outside the #macro before they are passed.

The following will reliably export information out of a #macro using arguments.
Of course, you don't need to define an object inside a #macro, though I have
here.

#version 3.7;
global_settings{assumed_gamma 1.0}
//
#include "colors.inc"
//
#macro in_and_out(num_in,num_out,vec_out,arr_out)
//
  #local num_out = num_in + 2;
  #local vec_out = <num_in+1,num_in+2,num_in+3>;
  #local icount  = 0;
  #while(icount < num_in)
    #local arr_out[icount] = icount+1;
    #local icount = icount + 1;
  #end
//
  sphere{<0,0,0> num_in pigment{Red}}
//
#end
//
#declare MMM_in  = 5;
#declare MMM_out = 0;
#declare MMM_vec = <0,0,0>;
#declare MMM_arr = array[MMM_in];
//
in_and_out(MMM_in,MMM_out,MMM_vec,MMM_arr)
//
sphere{MMM_vec, 1 pigment{Green}}
//
#warning concat("Last value of the array = ",str(MMM_arr[MMM_in-1],8,3))
//
light_source{ <100,100,-300>, 1}
//
camera{orthographic  location<0,0,-200> look_at <0,0,0> angle 15}


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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