I'm trying to create a function that returns only the second argument of Reap. Here's my naive guess of how it would go : Reap2[x_]:= Flatten[Reap[x][[2]],1]
However, even when X contains Sow, my function always returns empty.
I've made a simplified version here, which shows what I mean.
Reap[Sow[1]]
{1, {{1}}}
Clear[Reap2];
Reap2[x_] := Reap[x]
Reap2[Sow[1]]
{1, {}}
Can anyone explain this behavior? How would I go about building this function?
HoldFirst. Try:SetAttributes[Reap2, HoldFirst]. – Mr.Wizard Dec 12 '14 at 19:05Reapis not a simple function. It is closer to scoping constructs in spirit. It has aHoldattribute, so that the code evaluates only inside of it, but not before being passed. You need to setHoldAllorHoldFirstattribute to yourReap2, if you want it to behave properly. – Leonid Shifrin Dec 12 '14 at 19:05JoinandFlatten. – Mr.Wizard Dec 12 '14 at 19:38