       Re: mathematica question

• To: mathgroup at smc.vnet.net
• Subject: [mg9221] Re: [mg9199] mathematica question
• Date: Fri, 24 Oct 1997 01:00:34 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```>Hello Mathematica users,
>
>I have a question that I hope someone has an answer for.  I think it
>should be simple but I cannot find a way to make it work.
>
>I have a set of functions that take no inputs, they are called q1[],
>q2[], q3[] and so on.
>
>How can I get Mathematica to run the correct function given a list of
>numbers as input.  IE, if I supply the list {1,4,7,8} I would want
>Mathematica to run the functions q1[], q4[], q7[] and q8[], assuming
>they were defined.
>
>I would appreciate any assistance you might have with this!!
>
>Sincerely,
>
>Tom De Vries

Hello Tom,

You can try

In:=
theqMap[thelist_List] := Map[ ToExpression["q"<>ToString[#]<>"[]"]&,
thelist]

In:=
theqMap[{1,4,7,8}]

Out:=
{q1[],q2[],q3[],q4[]}

(this will also work if you use coherently something else than a number
such as a symbol).
but why not define these various functions as q,q... ? It would
allow you to use Map directly and this is in the spirit of the
Mathematica Language. You are not forced to supply a behavior for every
integer or every possible input: just type them as you need them. Also
if you don't want to have as result a list of the various results of
the function, but only the execution of the various functions, use Scan