Message Boards Message Boards

2 Replies
0 Total Likes
View groups...
Share this post:

Understand Reap output?

If I type the example given in help:

Reap[Sow[a]; b; Sow[c]; Sow[d]; e]

the output is:


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?


POSTED BY: David Silverman
2 Replies

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 BY: David Reiss

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...

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract