any way to access function..n?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 819
Joined: Sun Feb 14, 2010 7:11 pm

any way to access function..n?

Post by Bugala » Sun Jul 16, 2017 3:01 pm

I happen to have a situation where it would be very convinient to be using "for n=1 to x" to perform what I am doing, however, i have basically double trouble.

part of the line is to access func1, func2, func3.

And another is var1, var2, var3 type of thing.

so what i would in effect need is:

Code: Select all

for n=1 to 3
myfunction(var..n, func..n)
next
For var1, var2, i could see a possibility for using g["var"..n] to access it, but in this case they happen to be local variables, i guess local variables are not stored in global variables list at any point?

So any possiblity to access these without putting them first in list?

for i could have:

Code: Select all

myfunclist = {func1, func2, func3}
myvarlist = {var1, var2, var3}
and then access it:

Code: Select all

for n=1 to 3
myfunction(myvarlist[n], myfunclist[n]
next n
But is this the only way i can do it?

SamuraiCrow
Posts: 237
Joined: Fri May 15, 2015 5:15 pm
Location: Ft. Collins, Colorado USA

Re: any way to access function..n?

Post by SamuraiCrow » Mon Jul 17, 2017 5:53 pm

Of course there are other ways but the most effective way would be to make your existing wrapper tables into one so that each entry would have a var and a func field.

Code: Select all

wrap={{var=v1,func=func1},{var=v2,func=func2}…}
Then call it with

Code: Select all

wrap[n]["var"]
or

Code: Select all

wrap[n]["func"]
.

Post Reply