POV-Ray : Newsgroups : povray.general : Automatically named identifiers Server Time
23 Nov 2024 19:10:53 EST (-0500)
  Automatically named identifiers (Message 4 to 13 of 13)  
<<< Previous 3 Messages Goto Initial 10 Messages
From: Bald Eagle
Subject: Re: Automatically named identifiers
Date: 5 Nov 2024 08:05:00
Message: <web.672a17d8523ee1846563700825979125@news.povray.org>
"Thomas Fester" <tfe### [at] scivitde> wrote:
> Hello everybody: I have got a (seemingly) simple programing question: Suppose I
> I want to declare a number of splines in a loop-process with one spline per
> loop. The splines should have identifiers like SplineXA, SplineXB, SplineXC and
> so on. Is there a way to automatically generate such names within the loops?

You're going to have to use parse_string to make the variable name in each
iteration.
Concat "SplineX" with the char corresponding to the letter you want.

I'm hoping there are some examples if you search for them.

- BW


Post a reply to this message

From: Cousin Ricky
Subject: Re: Automatically named identifiers
Date: 5 Nov 2024 08:55:07
Message: <672a23bb$1@news.povray.org>
On 2024-11-04 18:52 (-4), Thomas Fester wrote:
> Hello everybody: I have got a (seemingly) simple programing question: Suppose I
> I want to declare a number of splines in a loop-process with one spline per
> loop. The splines should have identifiers like SplineXA, SplineXB, SplineXC and
> so on. Is there a way to automatically generate such names within the loops? At
> the moment I am only able to explicitely generate every identifier on its own.
> To make it more clear: Is it possible to have a loop for:

Would an array of splines serve your purpose?

#for (I, 0, 3)
  #declare SplineXs[I] = spline {
    cubic_spline
    ...
  }
#end


Post a reply to this message

From: Kenneth
Subject: Re: Automatically named identifiers
Date: 5 Nov 2024 12:15:00
Message: <web.672a5258523ee18491c33a706e066e29@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
>
> You're going to have to use parse_string to make the variable name in each
> iteration.
> Concat "SplineX" with the char corresponding to the letter you want.
>

My own initial (naive) approach to this would be to try and use the Parse_String
macro to the *left* of the = sign, in a #declare. (The macro -- in "strings.inc"
-- takes a string like "MY_VALUE" or "1.5", writes it to an external .tmp file
but without the double quotes, then immediately returns it to the scene.)

So a *simple* example of such a construct would seem to be...

#include "strings.inc"
#declare Parse_String("MY_VALUE")= 27;

I would naively expect this to be the equivalent of...
#declare MY_VALUE = 27;

but it doesn't work: ""Expected 'undeclared identifier', macro identifier found
instead."

I tried other iterations of this and they all fail.

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.


Post a reply to this message

From: Leroy
Subject: Re: Automatically named identifiers
Date: 5 Nov 2024 16:20:00
Message: <web.672a8b41523ee184a196c5bf712fc00@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
> >
> > You're going to have to use parse_string to make the variable name in each
> > iteration.
> > Concat "SplineX" with the char corresponding to the letter you want.
> >
>
> My own initial (naive) approach to this would be to try and use the Parse_String
> macro to the *left* of the = sign, in a #declare. (The macro -- in "strings.inc"
> -- takes a string like "MY_VALUE" or "1.5", writes it to an external .tmp file
> but without the double quotes, then immediately returns it to the scene.)
>
> So a *simple* example of such a construct would seem to be...
>
> #include "strings.inc"
> #declare Parse_String("MY_VALUE")= 27;
>
> I would naively expect this to be the equivalent of...
> #declare MY_VALUE = 27;
>
> but it doesn't work: ""Expected 'undeclared identifier', macro identifier found
> instead."
>
> I tried other iterations of this and they all fail.
>
> 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
Have Fun!


Post a reply to this message

From: Kenneth
Subject: Re: Automatically named identifiers
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

From: Thomas Fester
Subject: Re: Automatically named identifiers
Date: 6 Nov 2024 16:20:00
Message: <web.672bdc61523ee1846c6071e48a2a825f@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:
> "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.

Wow - I'm thrilled so many answers! Thank you all!


Post a reply to this message

From: kurtz le pirate
Subject: Re: Automatically named identifiers
Date: 7 Nov 2024 04:31:53
Message: <672c8909$1@news.povray.org>
On 06/11/2024 21:45, Kenneth wrote:

> 
> 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.
> 


Have you looked my method ?



-- 
kurtz le pirate
compagnie de la banquise


Post a reply to this message

From: Kenneth
Subject: Re: Automatically named identifiers
Date: 7 Nov 2024 11:55:00
Message: <web.672cef10523ee18491c33a706e066e29@news.povray.org>
kurtz le pirate <kur### [at] freefr> wrote:
> On 06/11/2024 21:45, Kenneth wrote:
>
> >
> > It would be an interesting exercise to try and re-code the macro itself,
> > to see if [the Parse_String macro] could be made to deal with multiple
> > entries...and to create multiple written .tmp files as well.
> >
>
> Have you looked my method ?
>

Oh! You already solved that, wow. And *without* creating multiple .tmp files. I
apologize for not grasping what what your code does; I took only a cursory
glance at it while I was working out my own tests. (The beginning of your code
kind of threw me off...
       // name of include file containing splines
          #declare FileName = "Splines.inc";

I mistakenly thought that you were somehow manipulating the *original*
splines.inc include file; sorry!)

So your code actually writes *multiple* #declares to the same .tmp file (called
Splines.inc), to be used later. Excellent.

Thanks for (re-)calling my attention to it. ;-)

-----
BTW: Sorry, Thomas, for calling you Warren. I don't know where *that* came from!
:-O


Post a reply to this message

From: Kenneth
Subject: Re: Automatically named identifiers
Date: 7 Nov 2024 13:10:00
Message: <web.672d025b523ee18491c33a706e066e29@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:
>
> 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:
>
> ...
>
> #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>;
>

Actually, that one #declare would mistakenly be...
    declare MY_VECTOR_3 = <.3,.5,.8>;
(no hash symbol at the beginning)

The Parse_String line above should have been this:

Parse_String(concat("#declare MY_VECTOR_",...

Sorry for the syntax mistake.


Post a reply to this message

From: kurtz le pirate
Subject: Re: Automatically named identifiers
Date: 9 Nov 2024 06:26:45
Message: <672f46f5$1@news.povray.org>
On 07/11/2024 17:49, Kenneth wrote:
>         // name of include file containing splines
>            #declare FileName = "Splines.inc";
> 
> I mistakenly thought that you were somehow manipulating the*original*
> splines.inc include file; sorry!)


Sorry for my clumsy choice for the file name.




-- 
kurtz le pirate
compagnie de la banquise


Post a reply to this message

<<< Previous 3 Messages Goto Initial 10 Messages

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