| Author |
Comment/Response |
Dmitry
|
05/11/12 08:19am
Hi,
I often use Reap and Sow, and do not understand why does Reap's output have different structure depending on the collected result.
If nothing was collected, then the result of reaping is {}. If something was collected, then the result is additionally "wrapped" into a redundant List: {{collected items}}. This relates to both using Reap with and without patterns.
So when I get the collecting results, I have to check whether the list is empty, and if not, take its first element as the list of collected items.
I wrote a function which does this check and returns the results in a proper form (the code is below). But I do not understand, WHY?
SetAttributes[myReap, HoldAllComplete];
myReap[e__] := Module[{r, l},
r = Reap[e];
If[r[[2]] == {}, {},
If[Length[Hold[e]] == 1 || Head[Hold[e][[2]]] =!= List,
r[[2, 1]],
If[# == {}, {}, First[#]] & /@ r[[2]]
]
]
];
URL: , |
|