Re: lists of variables
- To: mathgroup at smc.vnet.net
- Subject: [mg58178] Re: lists of variables
- From: "dkr" <dkrjeg at adelphia.net>
- Date: Tue, 21 Jun 2005 06:02:53 -0400 (EDT)
- References: <d9630u$q1t$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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.