POV-Ray : Newsgroups : povray.advanced-users : Can strings be used to create identifiers? : Re: Can strings be used to create identifiers? Server Time
28 May 2024 21:18:25 EDT (-0400)
  Re: Can strings be used to create identifiers?  
From: Alain
Date: 22 Feb 2014 21:19:09
Message: <53095a9d$1@news.povray.org>

> Is it possible to use a string construction of some kind to generate a VARIABLE
> NAME (or identifier, as POV-Ray calls it) that can be used after a #declare?
>
> So that, instead of
> #declare my_value = 12345;
> I could do this...
> #declare --generated string name-- = 12345;
>
> So far, I have had no luck. (Maybe I'm forgetting something basic??)
>
> As a more practical example, say I want to create 100 different arrays inside of
> a #while loop-- each with a different #declared name of course-- but without
> having to manually name each and every array. Creating the different names
> themselves is no problem when using strings (assume that AC is a #while loop
> counter, simple up-counting integers)...
>
> #declare array_name = concat("my_array",str(AC,1,0))
>
> The generated string changes as AC changes, and array_name becomes my_array1,
> my_array2, etc. But these are just names-as-strings, with no arrays 'attached'
> yet. When I then try to create the arrays themselves...
>
> #declare array_name = array[100]
>
> ......array_name is just #re-declared at every count of the while loop (it
> doesn't substitute my_array1 for it, then my_array2 etc) which defeats the idea;
> the end result is a *single* array that's simply re-declared over and over
> again.
>
> Trying to simplify the idea to this rather strange construction doesn't work
> either (it produces a fatal error)...
>
> #declare concat("my_array",str(AC,1,0)) = array[100]
>
> So, if not with strings, is there another way to do this kind of automated
> identifier creation?
>
> ------
> While I'm on this subject: I see that I cannot substitute a string for one of
> POV-Ray's built-in keywords-- like rgb or whatever. For example:
>
> #declare color_vector_type = "rgb"
>
> which I could then use in a pigment statement...
>
> pigment{color_vector_type <.3,.6,.9>}
>
> I would have assumed that this was possible, simply because... 'text is text':
> When I type the letters rgb on the keyboard, its just text. (But then, of
> course, POV-Ray recognizes what I've typed, and substitutes a keyword for it.)
> So... what are the essential differences between typing r-g-b, the string "rgb",
> and the keyword rgb? Perhaps it's a very naive question! (Maybe one that would
> require a textbook in C-programming to explain??)
>
>
>
>

Write the generated names to an inc file. The generated files need to 
contain ONLY the name of a single array.

Next, whenever you need to use one of the generated names, #include the 
corresponding file.


For the second question, no, text is not always text. It depends on the 
context.
For POV-Ray, "This_is_some_text" IS text while #declare 
This_is_some_text is a user defined identifier.
If you want to use color_vector_typ as a substitute for rgb=, you need 
to define a macro.

#macro color_vector_type()  rgb= #end
pigment{color_vector_type() <.3,.6,.9>}

The empty parentheses are mandatory.



Alain


Post a reply to this message

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