Re: Question on Thread
- To: mathgroup at smc.vnet.net
- Subject: [mg64459] Re: [mg64418] Question on Thread
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Fri, 17 Feb 2006 04:12:59 -0500 (EST)
- References: <200602160805.DAA29888@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 16 Feb 2006, at 09:05, Matt wrote: > Hello, > > Clear[f] > Thread[(f[#1, #2] & )[{1, 2, 3}, {{a, 1}, {b, 2}, {c, 3}}]] > > Gives the expected output, i.e. {f[1,{a,1}], f[2,{b,2}],...} > > but > > Clear[f, g] > Thread[(f[g[#1], #2] & )[{1, 2, 3}, {{a, 1}, {b, 2}, {c, 3}}]] > > gives me: > > f[g[{1, 2, 3}], {a, 1}], f[g[{1, 2, 3}], {b, 2}], ..., etc. > > whereas I would have expected: > > f[g[1], {a, 1}], f[g[2], {b, 2}], ..., etc. > > I've looked at the 'Thread' documentation and in the Mathematica Book, > but I can't see why the second case doesn't work. > > BTW, I used MapThread as follows, which does work: > > MapThread[f[g[#1], #2] & , {{1, 2, 3}, {{a, 1}, {b, 2}, {c, 3}}} > > Thanks for your time, > > Matt > The reason is that Thread evaluates its arguments. Use In[7]:= Thread[Unevaluated[(f[g[#1], #2] & )[{1, 2, 3}, {{a, 1}, {b, 2}, {c, 3}}]]] Out[7]= {f(g(1),{a,1}),f(g(2),{b,2}),f(g(3),{c,3})} Andrzej Kozlowski
- References:
- Question on Thread
- From: "Matt" <anonmous69@netscape.net>
- Question on Thread