Re: Thread and Set
- To: mathgroup at smc.vnet.net
- Subject: [mg14576] Re: [mg14537] Thread and Set
- From: Des Penny <penny at suu.edu>
- Date: Fri, 30 Oct 1998 03:07:44 -0500
- Organization: Southern Utah University
- References: <199810290933.EAA21697@smc.vnet.net.>
- Sender: owner-wri-mathgroup at wolfram.com
Alex:
Set has Attributes:
In[1]:=
Attributes[Set]
Out[1]=
{HoldFirst,Protected,SequenceHold}
In this case you want to override the HoldFirst Attribute in order to
evaluate the argument. The following will work:
In[2]:=
Clear[a,b]
vars={a,b};
nums={1,2};
Thread[Set[Evaluate[vars],nums]];
{a,b}
Out[3]=
{1,2}
Cheers,
Des Penny
Alex Tabarrok wrote:
> I'd like to use Thread and Set to define a number of variables. The
> following works as expected:
>
> In[86]:=Clear[a,b]
> In[87]:=Thread[Set[{a,b},{1,2}]]
> Out[87]={1,2}
> In[88]:=a
> Out[88]=1
> In[89]:=b
> Out[89]=2
>
> But why doesn't the following work?
>
> In[101]:=Clear[a,b]
> In[102]:=vars={a,b}
> Out[102]={a,b}
> In[103]:=nums={1,2}
> Out[103]={1,2}
> In[104]:=Thread[Set[vars,nums]]
> Out[104]={1,2}
> In[105]:=a
> Out[105]=a
> In[106]:=b
> Out[106]=b
> In[107]:=vars
> Out[107]={1,2}
>
> thanks in advance
>
> Alex
>
> Alex Tabarrok
> Department of Economics
> Ball State University
> 00ATTabarrok at bsuvc.bsu.edu
- References:
- Thread and Set
- From: Alex Tabarrok <00attabarrok@bsuvc.bsu.edu>
- Thread and Set