POV-Ray : Newsgroups : povray.general : Automatically named identifiers : Re: Automatically named identifiers Server Time
21 Nov 2024 04:53:28 EST (-0500)
  Re: Automatically named identifiers  
From: Kenneth
Date: 6 Nov 2024 15:50:00
Message: <web.672bd56a523ee18491c33a706e066e29@news.povray.org>
"Leroy" <whe### [at] gmailcom> wrote:
> "Kenneth" <kdw### [at] gmailcom> wrote:

> >
> > Maybe there are other (more complex?) ways of using Parse_String to accomplish
> > what the OP wants-- *as* the #declared variable names-- but I don't have
> > a clue as to how.
>
> #include "strings.inc"
> Parse_String("#declare I")=4;
> #debug concat("I =",str(I,0,0),"\n")
>
> works fine  on win3.7 version
>
> Parse_String("#declare I=4;") also works ok

Aha! So a variable name CAN be auto-generated. Excellent. (These also work
successfully in v3.8 beta 1.) I didn't think to try your iterations earlier; I
was, uh, rushed for time yesterday :-[  (Well, that's my excuse anyway, ha)

Unfortunately, even these would not solve Warren's initial query of
auto-creating *multiple* #declares, at least not efficiently.

Here's a #for-loop example that might *seem* to be a way to do it. Even though
it works code-wise as SDL, the result is not what might be expected:

[I used simple vectors here instead of Warren's splines]
#declare My_Vector_Array=array[3] // 'bins' 0 to 2 inclusive
#declare My_Vector_Array[0]= <.1,.3,.6>;
#declare My_Vector_Array[1]= <.2,.4,.7>;
#declare My_Vector_Array[2]= <.3,.5,.8>;

#for(i,1,3)
Parse_String(concat("declare MY_VECTOR_",str(i,0,0)," = <",
vstr(3,My_Vector_Array[i-1],", ",0,1),">;"))
#end

This actually creates only ONE #declare, the final one:
#declare MY_VECTOR_3 = <.3,.5,.8>;

The Parse_String macro always #writes its result to a *single* file named
parse_string.tmp  (in Windows anyway); so in the for-loop, each result simply
gets over-written by the next one.

It would be an interesting exercise to try and re-code the macro itself, to see
if it could be made to deal with multiple entries...and to create multiple
written .tmp files as well.


Post a reply to this message

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