MathGroup Archive 2005

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

Search the Archive

Re: lists of variables


As an addendum to my previous reply, the following example shows one
way you can use the list of variables in defining functions:

In[46]:=
var=ToExpression[Map["t"<>ToString[#]&,Range[3]]]
Out[46]=
{t1,t2,t3}

In[47]:=
f[Sequence@@Map[Function[Pattern[#,Blank[]]],var]]=Plus[Sequence@@var];

In[48]:=f[1,2,3]
Out[48]=6

Note that Set, not SetDelayed, has been used in the function
definition, since var on the righthand side must be evaluated before
pattern matching occurs.


  • Prev by Date: Re: associative arrays
  • Next by Date: Re: lists of variables
  • Previous by thread: Re: lists of variables
  • Next by thread: Re: lists of variables