Dynamic assignment of list name in iterator statement?

James McMahon <[email protected]>
Newsgroups gmane.comp.lang.groovy.user
Message-ID <CAEqJCe0Tpti5rzN57NwqfPL_uoRwTsPmQCWz6h7o8ikQRhcn7w@mail.gmail.com>
Good evening. I have a list named languageCharactersList. I begin my
iteration through elements in that list with this:

languageCharactersList.eachWithIndex( it, i ->

I hope to make this more generic, so that I can build a variable name that
points to the appropriate list, which then allows me to keep my iteration
loop generic.

I'd like to do this:
def languages = ['english', 'french', 'spanish']
def englishCharsList = [....]
def frenchCharsList = [.....]
def spanishCharsList = [....]

I'll set up an iterator to grab each of the languages. Within that
iterative loop I will set a general variable like so:
def CharsList = "english"+"CharsList" (then "french", then "spanish",.....)

I was hoping I could then set up the generic iterator like so:
*"$CharsList"*.eachWithIndex{ it, i ->
or like so
*$CharsList*.eachWithIndex{ it, i ->

But Groovy doesn't allow this approach, and throws a stack trace.

How can we employ a variable assignment in that list iterator statement
so it can be generalized?

Thanks in advance.
Jim
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.