Re: [Csnd-dev] convert string to variable name

vlz <[email protected]>
Newsgroups gmane.comp.audio.csound.devel
Message-ID <[email protected]>
It’s possible to create a new variable but you need to recompile the code.
> On 10 Aug 2025, at 10:20, joachim heintz <[email protected]> wrote:
> 
> is it possible to convert a string to a variable name in csound 7?
> use case:
> 
> // having two string variable names
> arr_1:i[] = [1,2,3]
> arr_2:i[] = [4,5,6]
> // s will be either "arr_1" or "arr_2"
> s:S = sprintf("arr_%d",int(random:i(1,2.9999)))
> // the (not existing) opcode str2var would convert to the variable name
> myvar = str2var(s)
> // so now i can use myvar
> print(myvar[0])
> 
> or something like python's eval() in csound?
> 
> (i tried the existing opcode evalstr but could not get to what i need.)
> 
> thanks -
> joachim
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.