Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Thread and Set

  • To: mathgroup at smc.vnet.net
  • Subject: [mg14568] Re: Thread and Set
  • From: "P.J. Hinton" <paulh>
  • Date: Fri, 30 Oct 1998 03:07:38 -0500
  • Organization: "Wolfram Research, Inc."
  • References: <719f85$lcb@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 29 Oct 1998, 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}

The behavior you're observing is due to the fact that Set[] has the
attribute HoldFirst.  Try wrapping Evaluate[] around vars.

In[1]:= vars={a,b}

Out[1]= {a, b}

In[2]:= nums={1,2}

Out[2]= {1, 2}

In[3]:= Thread[Set[Evaluate[vars], nums]]

Out[3]= {1, 2}

In[4]:= a

Out[4]= 1

In[5]:= b

Out[5]= 2

--
P.J. Hinton
Mathematica Programming Group           paulh at wolfram.com Wolfram
Research, Inc.                  http://www.wolfram.com/~paulh/
Disclaimer: Opinions expressed herein are those of the author alone.



  • Prev by Date: Re: Can I get ComplexExpand to really work?
  • Next by Date: Re: beep after calculation
  • Previous by thread: Re: Thread and Set
  • Next by thread: Newton-Raphson Method