any way to access function..n?

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

any way to access function..n?

Post by Bugala »

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: 475
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: any way to access function..n?

Post by SamuraiCrow »

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"]
.
I'm on registered MorphOS using FlowStudio.
Post Reply