MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: mathematica question

>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!!
>Tom De Vries

Hello Tom,

You can try

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



(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[1],q[4]... ? 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
instead of Map.

Olivier Gerard

  • Prev by Date: Re: Help with GraphicsArray
  • Next by Date: Submitting articles to The Mathematica Journal
  • Previous by thread: Re: mathematica question
  • Next by thread: UNIX to PC problems