0
|
3448 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
GROUPS:

# Understand Reap output?

Posted 8 years ago
 If I type the example given in help: Reap[Sow[a]; b; Sow[c]; Sow[d]; e]  the output is: {e,{{a,c,d}}}  I understand the {a,c,d} part as those were Sown. I don't understand why there are double braces around it though. BUT my main question is where did the "e" come from at the beginning? I see it in the Reap input, but it is never Sown, so why is it included? Thanks
2 Replies
Sort By:
Posted 8 years ago
 The e is the result of the evaluation in the argument of Reap. The reason for the extra set of braces in {{a,c,d}} is that for what was Sown, Reap returns a list of lists--in this case there is only one, but this allows for the other argument forms of Reap to work consistent with this simple form.
Posted 8 years ago
 To add to David's reply: Reap[Sow[1, {x, x}]; Sow[2, y]; Sow[3, x]; 2 + 2] {4, {{1, 1, 3}, {2}}} 1 is 'sown' twice with tag x, then 2 is sown once with tag y, and then 3 is sown with tag 'x'. Now for each tag it is 'reaped'. That is the reason for the list of the lists...