Re: Re: Re: Threading 'Append'
- To: mathgroup at smc.vnet.net
- Subject: [mg62887] Re: [mg62849] Re: [mg62834] Re: [mg62796] Threading 'Append'
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Thu, 8 Dec 2005 00:04:13 -0500 (EST)
- References: <200512051840.NAA21108@smc.vnet.net> <200512060504.AAA02838@smc.vnet.net> <200512070410.XAA23689@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 7 Dec 2005, at 13:10, Pratik Desai wrote: > Andrzej Kozlowski wrote: > >> On 6 Dec 2005, at 03:40, J Siehler wrote: >> >> >> >>> If I run >>> >>> Thread[Append[{{1,2},{3,4},{5,6}},{a,b,c}]] >>> >>> I would expect to get >>> >>> {{1,2,a},{3,4,b},{5,6,c}} >>> >>> but in fact I get an 'Objects of unequal length' error. >>> >>> On the other hand, >>> >>> Thread[foo[{{1,2},{3,4},{5,6}},{a,b,c}]] >>> %/.foo->Append >>> >>> gives what I wanted. Can someone explain what's going on? >>> >>> >>> >> >> All you need to do is: >> >> In[9]:= >> Thread[Unevaluated[Append[{{1, 2}, {3, 4}, {5, 6}}, >> {a, b, c}]]] >> >> Out[9]= >> {{1, 2, a}, {3, 4, b}, {5, 6, c}} >> >> >> The name of the function "Unevaluated" should make it self evident >> what happened here (I hope). >> >> > Actually it is not. Can you please elaborate > > Pratik > Actually, I meant that what was self evident was that the problem was because Append[.....] was *evaluated*. The actual mechanism of Unevaluated is quite tricky. Basically it is first stripped off and then the code beginning with Append is passed unevaluated to Thread. Then Appended is threaded as desired. After than the "evaluator" once again looks at the expression to see if it had undergone a change. Since it did, it does not put back the head Unevaluated. So much in theory, and it actually works here exactly as advertised. But there are cases when it works in a much more complicated way. Andrzej Kozlowski
- References:
- Threading 'Append'
- From: "J Siehler" <jsiehler@Gmail.com>
- Re: Threading 'Append'
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Re: Threading 'Append'
- From: Pratik Desai <pdesai1@umbc.edu>
- Threading 'Append'