Understanding Sow and Reap documentation

Multi tool use
Clash Royale CLAN TAG#URR8PPP
up vote
16
down vote
favorite
Both in Sow
and in Reap
documentation there is the example:
Reap[Sow[a]; b; Sow[c]; Sow[d]; e]
which gives the result e,a,c,d
. What happens to b
?
documentation sow-reap
add a comment |Â
up vote
16
down vote
favorite
Both in Sow
and in Reap
documentation there is the example:
Reap[Sow[a]; b; Sow[c]; Sow[d]; e]
which gives the result e,a,c,d
. What happens to b
?
documentation sow-reap
4
;
is the same asCompoundExpression
which returns the last argument. E.g.b; e
returnse
. What output did you expect?
– Coolwater
Sep 10 at 8:20
It's ignored because it's followed by;
. This has nothing to do withSow
/Reap
. It's not clear to me what you are asking / expecting.
– Szabolcs
Sep 10 at 9:24
1
@mattiav27 Maybe you are actually looking for something like this:Reap[ Sow[a, "list1"]; Sow[b, "list2"]; Sow[c, "list1"]; Sow[d, "list1"]; Sow[e, "list2"], _, Rule ]
? This uses tags to tell to which list a sown expression should be appended.
– Henrik Schumacher
Sep 10 at 9:31
add a comment |Â
up vote
16
down vote
favorite
up vote
16
down vote
favorite
Both in Sow
and in Reap
documentation there is the example:
Reap[Sow[a]; b; Sow[c]; Sow[d]; e]
which gives the result e,a,c,d
. What happens to b
?
documentation sow-reap
Both in Sow
and in Reap
documentation there is the example:
Reap[Sow[a]; b; Sow[c]; Sow[d]; e]
which gives the result e,a,c,d
. What happens to b
?
documentation sow-reap
documentation sow-reap
edited Sep 10 at 10:11
gwr
6,82322356
6,82322356
asked Sep 10 at 8:09
mattiav27
2,03211429
2,03211429
4
;
is the same asCompoundExpression
which returns the last argument. E.g.b; e
returnse
. What output did you expect?
– Coolwater
Sep 10 at 8:20
It's ignored because it's followed by;
. This has nothing to do withSow
/Reap
. It's not clear to me what you are asking / expecting.
– Szabolcs
Sep 10 at 9:24
1
@mattiav27 Maybe you are actually looking for something like this:Reap[ Sow[a, "list1"]; Sow[b, "list2"]; Sow[c, "list1"]; Sow[d, "list1"]; Sow[e, "list2"], _, Rule ]
? This uses tags to tell to which list a sown expression should be appended.
– Henrik Schumacher
Sep 10 at 9:31
add a comment |Â
4
;
is the same asCompoundExpression
which returns the last argument. E.g.b; e
returnse
. What output did you expect?
– Coolwater
Sep 10 at 8:20
It's ignored because it's followed by;
. This has nothing to do withSow
/Reap
. It's not clear to me what you are asking / expecting.
– Szabolcs
Sep 10 at 9:24
1
@mattiav27 Maybe you are actually looking for something like this:Reap[ Sow[a, "list1"]; Sow[b, "list2"]; Sow[c, "list1"]; Sow[d, "list1"]; Sow[e, "list2"], _, Rule ]
? This uses tags to tell to which list a sown expression should be appended.
– Henrik Schumacher
Sep 10 at 9:31
4
4
;
is the same as CompoundExpression
which returns the last argument. E.g. b; e
returns e
. What output did you expect?– Coolwater
Sep 10 at 8:20
;
is the same as CompoundExpression
which returns the last argument. E.g. b; e
returns e
. What output did you expect?– Coolwater
Sep 10 at 8:20
It's ignored because it's followed by
;
. This has nothing to do with Sow
/Reap
. It's not clear to me what you are asking / expecting.– Szabolcs
Sep 10 at 9:24
It's ignored because it's followed by
;
. This has nothing to do with Sow
/Reap
. It's not clear to me what you are asking / expecting.– Szabolcs
Sep 10 at 9:24
1
1
@mattiav27 Maybe you are actually looking for something like this:
Reap[ Sow[a, "list1"]; Sow[b, "list2"]; Sow[c, "list1"]; Sow[d, "list1"]; Sow[e, "list2"], _, Rule ]
? This uses tags to tell to which list a sown expression should be appended.– Henrik Schumacher
Sep 10 at 9:31
@mattiav27 Maybe you are actually looking for something like this:
Reap[ Sow[a, "list1"]; Sow[b, "list2"]; Sow[c, "list1"]; Sow[d, "list1"]; Sow[e, "list2"], _, Rule ]
? This uses tags to tell to which list a sown expression should be appended.– Henrik Schumacher
Sep 10 at 9:31
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
25
down vote
accepted
I'll be totally honest with you and admit that I had no idea how these functions worked (or what the point of them was) for a long time, so you're not alone in your struggle trying to understand the documentation here. This is one of those things where you first need to build the right mental picture of the language before you can start making sense of the code you're seeing here.
In this situation, it's very important that you understand the difference between a returned value and a side effect. I'll take a rather large detour here before I get back to Sow
and Reap
, so please bear with me.
Every time an expression is evaluated, it produces a return value. So, for example, the expression 1
simply returns 1
and 1 + 1
returns 2
. There is, however, also a special return value called Null
which indicates that "nothing" was returned. In particular, if Null
is returned from an evaluation, no output cell will be printed in the notebook. The most well-known way to suppress any return value and turn it into Null
, is by finishing your input with ;
.
If you type the expression in a notebook cell, the return value will get printed in a new cell below the input except if the returned values is Null
. You can still test that the returned value really is Null
:
In[1]:= (1 + 1;) === Null
Out[1]= True
So what happens when you enter multiple expressions separated by semicolons? This is what is known in Mathematica as a CompoundExpression
. You can verify this with Hold
and FullForm
:
In[2]:= Hold[
1 + 1;
3
] // FullForm
Out[2]= Hold[CompoundExpression[1 + 1, 3]]
A compound expression simply evaluates each argument in turn and then returns the last result. You'll notice that if you finish the last expression with a semicolon as well, a Null
will be tagged on the end:
In[3]:= Hold[1 + 1; 3;] // FullForm
Out[3]= Hold[CompoundExpression[1 + 1, 3, Null]]
In this example, the 1 + 1
expression is really quite meaningless: it gets evaluated (if you remove the Hold
, of course), but the result is never returned: it is simply forgotten about.
So is there any value in using CompoundExpression
to chain expressions together? Yes, there is, but typically only when the expressions that don't get returned have side effects. The term "side effect" is basically an expensive-sounding term for things like variable/function assignment. If the evaluation of an expression changes how other expressions evaluate in the future, we say that we have produced a side effect. For example, if we evaluate x
, we simply get x
back:
In[4]:= x
Out[4]= x
However, if we Set
a value to x
by evaluating
In[5]:= x = 1
Out[5]= 1
(or equivalently Set[x, 1]
), 2 things happen:
x
is assigned a value (anOwnValue
, to be precise).- The value that was assigned to
x
is returned.
So Set
produces a side effect AND a return value. The the side effect is obvious, since the same input in cell 4 now produces a different output:
In[6]:= x
Out[6]= 1
To put everything together: when you chain up a compound expression like this:
expr1;
expr2;
expr3;
...
finalExpression
the idea is that all expressions expr1
, expr2
, ... etc. build up side effects that get used in the evaluation of finalExpression
.
Ok, so what does this mean for the example from the documentation?
In[7]:= Reap[Sow[a]; b; Sow[c]; Sow[d]; e]
Out[7]= e, a, c, d
We have seen that the inner expression is just
CompoundExpression[Sow[a], b, Sow[c], Sow[d], e]
and the return value of this is obvious: just the last argument e
. This is the value you see in as the first element in the list returned by Reap
.
The second element of the list returned by Reap
represents side effects from Sow
. All that Sow
does, is:
- Evaluate its argument
- Store the result (let's call it
value
) in some internal data structure (which is a side effect). In a sense, it just does something similar toAppendTo[reapList, value]
, but more efficiently. - return
value
as a return value
The job of Reap
is to collect all values stored inside of the internal data structure and spit it out in the second element of the list it returns.
Hopefully you now understand enough of the example to work out for yourself to read the rest of the Sow
/Reap
documentation to figure out how the tags work. It's a good exercise ;).
1
Thanks for the expalantion!
– mattiav27
Sep 10 at 10:23
Thanks for writing this!
– user6546
Sep 11 at 10:48
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
25
down vote
accepted
I'll be totally honest with you and admit that I had no idea how these functions worked (or what the point of them was) for a long time, so you're not alone in your struggle trying to understand the documentation here. This is one of those things where you first need to build the right mental picture of the language before you can start making sense of the code you're seeing here.
In this situation, it's very important that you understand the difference between a returned value and a side effect. I'll take a rather large detour here before I get back to Sow
and Reap
, so please bear with me.
Every time an expression is evaluated, it produces a return value. So, for example, the expression 1
simply returns 1
and 1 + 1
returns 2
. There is, however, also a special return value called Null
which indicates that "nothing" was returned. In particular, if Null
is returned from an evaluation, no output cell will be printed in the notebook. The most well-known way to suppress any return value and turn it into Null
, is by finishing your input with ;
.
If you type the expression in a notebook cell, the return value will get printed in a new cell below the input except if the returned values is Null
. You can still test that the returned value really is Null
:
In[1]:= (1 + 1;) === Null
Out[1]= True
So what happens when you enter multiple expressions separated by semicolons? This is what is known in Mathematica as a CompoundExpression
. You can verify this with Hold
and FullForm
:
In[2]:= Hold[
1 + 1;
3
] // FullForm
Out[2]= Hold[CompoundExpression[1 + 1, 3]]
A compound expression simply evaluates each argument in turn and then returns the last result. You'll notice that if you finish the last expression with a semicolon as well, a Null
will be tagged on the end:
In[3]:= Hold[1 + 1; 3;] // FullForm
Out[3]= Hold[CompoundExpression[1 + 1, 3, Null]]
In this example, the 1 + 1
expression is really quite meaningless: it gets evaluated (if you remove the Hold
, of course), but the result is never returned: it is simply forgotten about.
So is there any value in using CompoundExpression
to chain expressions together? Yes, there is, but typically only when the expressions that don't get returned have side effects. The term "side effect" is basically an expensive-sounding term for things like variable/function assignment. If the evaluation of an expression changes how other expressions evaluate in the future, we say that we have produced a side effect. For example, if we evaluate x
, we simply get x
back:
In[4]:= x
Out[4]= x
However, if we Set
a value to x
by evaluating
In[5]:= x = 1
Out[5]= 1
(or equivalently Set[x, 1]
), 2 things happen:
x
is assigned a value (anOwnValue
, to be precise).- The value that was assigned to
x
is returned.
So Set
produces a side effect AND a return value. The the side effect is obvious, since the same input in cell 4 now produces a different output:
In[6]:= x
Out[6]= 1
To put everything together: when you chain up a compound expression like this:
expr1;
expr2;
expr3;
...
finalExpression
the idea is that all expressions expr1
, expr2
, ... etc. build up side effects that get used in the evaluation of finalExpression
.
Ok, so what does this mean for the example from the documentation?
In[7]:= Reap[Sow[a]; b; Sow[c]; Sow[d]; e]
Out[7]= e, a, c, d
We have seen that the inner expression is just
CompoundExpression[Sow[a], b, Sow[c], Sow[d], e]
and the return value of this is obvious: just the last argument e
. This is the value you see in as the first element in the list returned by Reap
.
The second element of the list returned by Reap
represents side effects from Sow
. All that Sow
does, is:
- Evaluate its argument
- Store the result (let's call it
value
) in some internal data structure (which is a side effect). In a sense, it just does something similar toAppendTo[reapList, value]
, but more efficiently. - return
value
as a return value
The job of Reap
is to collect all values stored inside of the internal data structure and spit it out in the second element of the list it returns.
Hopefully you now understand enough of the example to work out for yourself to read the rest of the Sow
/Reap
documentation to figure out how the tags work. It's a good exercise ;).
1
Thanks for the expalantion!
– mattiav27
Sep 10 at 10:23
Thanks for writing this!
– user6546
Sep 11 at 10:48
add a comment |Â
up vote
25
down vote
accepted
I'll be totally honest with you and admit that I had no idea how these functions worked (or what the point of them was) for a long time, so you're not alone in your struggle trying to understand the documentation here. This is one of those things where you first need to build the right mental picture of the language before you can start making sense of the code you're seeing here.
In this situation, it's very important that you understand the difference between a returned value and a side effect. I'll take a rather large detour here before I get back to Sow
and Reap
, so please bear with me.
Every time an expression is evaluated, it produces a return value. So, for example, the expression 1
simply returns 1
and 1 + 1
returns 2
. There is, however, also a special return value called Null
which indicates that "nothing" was returned. In particular, if Null
is returned from an evaluation, no output cell will be printed in the notebook. The most well-known way to suppress any return value and turn it into Null
, is by finishing your input with ;
.
If you type the expression in a notebook cell, the return value will get printed in a new cell below the input except if the returned values is Null
. You can still test that the returned value really is Null
:
In[1]:= (1 + 1;) === Null
Out[1]= True
So what happens when you enter multiple expressions separated by semicolons? This is what is known in Mathematica as a CompoundExpression
. You can verify this with Hold
and FullForm
:
In[2]:= Hold[
1 + 1;
3
] // FullForm
Out[2]= Hold[CompoundExpression[1 + 1, 3]]
A compound expression simply evaluates each argument in turn and then returns the last result. You'll notice that if you finish the last expression with a semicolon as well, a Null
will be tagged on the end:
In[3]:= Hold[1 + 1; 3;] // FullForm
Out[3]= Hold[CompoundExpression[1 + 1, 3, Null]]
In this example, the 1 + 1
expression is really quite meaningless: it gets evaluated (if you remove the Hold
, of course), but the result is never returned: it is simply forgotten about.
So is there any value in using CompoundExpression
to chain expressions together? Yes, there is, but typically only when the expressions that don't get returned have side effects. The term "side effect" is basically an expensive-sounding term for things like variable/function assignment. If the evaluation of an expression changes how other expressions evaluate in the future, we say that we have produced a side effect. For example, if we evaluate x
, we simply get x
back:
In[4]:= x
Out[4]= x
However, if we Set
a value to x
by evaluating
In[5]:= x = 1
Out[5]= 1
(or equivalently Set[x, 1]
), 2 things happen:
x
is assigned a value (anOwnValue
, to be precise).- The value that was assigned to
x
is returned.
So Set
produces a side effect AND a return value. The the side effect is obvious, since the same input in cell 4 now produces a different output:
In[6]:= x
Out[6]= 1
To put everything together: when you chain up a compound expression like this:
expr1;
expr2;
expr3;
...
finalExpression
the idea is that all expressions expr1
, expr2
, ... etc. build up side effects that get used in the evaluation of finalExpression
.
Ok, so what does this mean for the example from the documentation?
In[7]:= Reap[Sow[a]; b; Sow[c]; Sow[d]; e]
Out[7]= e, a, c, d
We have seen that the inner expression is just
CompoundExpression[Sow[a], b, Sow[c], Sow[d], e]
and the return value of this is obvious: just the last argument e
. This is the value you see in as the first element in the list returned by Reap
.
The second element of the list returned by Reap
represents side effects from Sow
. All that Sow
does, is:
- Evaluate its argument
- Store the result (let's call it
value
) in some internal data structure (which is a side effect). In a sense, it just does something similar toAppendTo[reapList, value]
, but more efficiently. - return
value
as a return value
The job of Reap
is to collect all values stored inside of the internal data structure and spit it out in the second element of the list it returns.
Hopefully you now understand enough of the example to work out for yourself to read the rest of the Sow
/Reap
documentation to figure out how the tags work. It's a good exercise ;).
1
Thanks for the expalantion!
– mattiav27
Sep 10 at 10:23
Thanks for writing this!
– user6546
Sep 11 at 10:48
add a comment |Â
up vote
25
down vote
accepted
up vote
25
down vote
accepted
I'll be totally honest with you and admit that I had no idea how these functions worked (or what the point of them was) for a long time, so you're not alone in your struggle trying to understand the documentation here. This is one of those things where you first need to build the right mental picture of the language before you can start making sense of the code you're seeing here.
In this situation, it's very important that you understand the difference between a returned value and a side effect. I'll take a rather large detour here before I get back to Sow
and Reap
, so please bear with me.
Every time an expression is evaluated, it produces a return value. So, for example, the expression 1
simply returns 1
and 1 + 1
returns 2
. There is, however, also a special return value called Null
which indicates that "nothing" was returned. In particular, if Null
is returned from an evaluation, no output cell will be printed in the notebook. The most well-known way to suppress any return value and turn it into Null
, is by finishing your input with ;
.
If you type the expression in a notebook cell, the return value will get printed in a new cell below the input except if the returned values is Null
. You can still test that the returned value really is Null
:
In[1]:= (1 + 1;) === Null
Out[1]= True
So what happens when you enter multiple expressions separated by semicolons? This is what is known in Mathematica as a CompoundExpression
. You can verify this with Hold
and FullForm
:
In[2]:= Hold[
1 + 1;
3
] // FullForm
Out[2]= Hold[CompoundExpression[1 + 1, 3]]
A compound expression simply evaluates each argument in turn and then returns the last result. You'll notice that if you finish the last expression with a semicolon as well, a Null
will be tagged on the end:
In[3]:= Hold[1 + 1; 3;] // FullForm
Out[3]= Hold[CompoundExpression[1 + 1, 3, Null]]
In this example, the 1 + 1
expression is really quite meaningless: it gets evaluated (if you remove the Hold
, of course), but the result is never returned: it is simply forgotten about.
So is there any value in using CompoundExpression
to chain expressions together? Yes, there is, but typically only when the expressions that don't get returned have side effects. The term "side effect" is basically an expensive-sounding term for things like variable/function assignment. If the evaluation of an expression changes how other expressions evaluate in the future, we say that we have produced a side effect. For example, if we evaluate x
, we simply get x
back:
In[4]:= x
Out[4]= x
However, if we Set
a value to x
by evaluating
In[5]:= x = 1
Out[5]= 1
(or equivalently Set[x, 1]
), 2 things happen:
x
is assigned a value (anOwnValue
, to be precise).- The value that was assigned to
x
is returned.
So Set
produces a side effect AND a return value. The the side effect is obvious, since the same input in cell 4 now produces a different output:
In[6]:= x
Out[6]= 1
To put everything together: when you chain up a compound expression like this:
expr1;
expr2;
expr3;
...
finalExpression
the idea is that all expressions expr1
, expr2
, ... etc. build up side effects that get used in the evaluation of finalExpression
.
Ok, so what does this mean for the example from the documentation?
In[7]:= Reap[Sow[a]; b; Sow[c]; Sow[d]; e]
Out[7]= e, a, c, d
We have seen that the inner expression is just
CompoundExpression[Sow[a], b, Sow[c], Sow[d], e]
and the return value of this is obvious: just the last argument e
. This is the value you see in as the first element in the list returned by Reap
.
The second element of the list returned by Reap
represents side effects from Sow
. All that Sow
does, is:
- Evaluate its argument
- Store the result (let's call it
value
) in some internal data structure (which is a side effect). In a sense, it just does something similar toAppendTo[reapList, value]
, but more efficiently. - return
value
as a return value
The job of Reap
is to collect all values stored inside of the internal data structure and spit it out in the second element of the list it returns.
Hopefully you now understand enough of the example to work out for yourself to read the rest of the Sow
/Reap
documentation to figure out how the tags work. It's a good exercise ;).
I'll be totally honest with you and admit that I had no idea how these functions worked (or what the point of them was) for a long time, so you're not alone in your struggle trying to understand the documentation here. This is one of those things where you first need to build the right mental picture of the language before you can start making sense of the code you're seeing here.
In this situation, it's very important that you understand the difference between a returned value and a side effect. I'll take a rather large detour here before I get back to Sow
and Reap
, so please bear with me.
Every time an expression is evaluated, it produces a return value. So, for example, the expression 1
simply returns 1
and 1 + 1
returns 2
. There is, however, also a special return value called Null
which indicates that "nothing" was returned. In particular, if Null
is returned from an evaluation, no output cell will be printed in the notebook. The most well-known way to suppress any return value and turn it into Null
, is by finishing your input with ;
.
If you type the expression in a notebook cell, the return value will get printed in a new cell below the input except if the returned values is Null
. You can still test that the returned value really is Null
:
In[1]:= (1 + 1;) === Null
Out[1]= True
So what happens when you enter multiple expressions separated by semicolons? This is what is known in Mathematica as a CompoundExpression
. You can verify this with Hold
and FullForm
:
In[2]:= Hold[
1 + 1;
3
] // FullForm
Out[2]= Hold[CompoundExpression[1 + 1, 3]]
A compound expression simply evaluates each argument in turn and then returns the last result. You'll notice that if you finish the last expression with a semicolon as well, a Null
will be tagged on the end:
In[3]:= Hold[1 + 1; 3;] // FullForm
Out[3]= Hold[CompoundExpression[1 + 1, 3, Null]]
In this example, the 1 + 1
expression is really quite meaningless: it gets evaluated (if you remove the Hold
, of course), but the result is never returned: it is simply forgotten about.
So is there any value in using CompoundExpression
to chain expressions together? Yes, there is, but typically only when the expressions that don't get returned have side effects. The term "side effect" is basically an expensive-sounding term for things like variable/function assignment. If the evaluation of an expression changes how other expressions evaluate in the future, we say that we have produced a side effect. For example, if we evaluate x
, we simply get x
back:
In[4]:= x
Out[4]= x
However, if we Set
a value to x
by evaluating
In[5]:= x = 1
Out[5]= 1
(or equivalently Set[x, 1]
), 2 things happen:
x
is assigned a value (anOwnValue
, to be precise).- The value that was assigned to
x
is returned.
So Set
produces a side effect AND a return value. The the side effect is obvious, since the same input in cell 4 now produces a different output:
In[6]:= x
Out[6]= 1
To put everything together: when you chain up a compound expression like this:
expr1;
expr2;
expr3;
...
finalExpression
the idea is that all expressions expr1
, expr2
, ... etc. build up side effects that get used in the evaluation of finalExpression
.
Ok, so what does this mean for the example from the documentation?
In[7]:= Reap[Sow[a]; b; Sow[c]; Sow[d]; e]
Out[7]= e, a, c, d
We have seen that the inner expression is just
CompoundExpression[Sow[a], b, Sow[c], Sow[d], e]
and the return value of this is obvious: just the last argument e
. This is the value you see in as the first element in the list returned by Reap
.
The second element of the list returned by Reap
represents side effects from Sow
. All that Sow
does, is:
- Evaluate its argument
- Store the result (let's call it
value
) in some internal data structure (which is a side effect). In a sense, it just does something similar toAppendTo[reapList, value]
, but more efficiently. - return
value
as a return value
The job of Reap
is to collect all values stored inside of the internal data structure and spit it out in the second element of the list it returns.
Hopefully you now understand enough of the example to work out for yourself to read the rest of the Sow
/Reap
documentation to figure out how the tags work. It's a good exercise ;).
edited Sep 11 at 8:11
answered Sep 10 at 10:05


Sjoerd Smit
2,750514
2,750514
1
Thanks for the expalantion!
– mattiav27
Sep 10 at 10:23
Thanks for writing this!
– user6546
Sep 11 at 10:48
add a comment |Â
1
Thanks for the expalantion!
– mattiav27
Sep 10 at 10:23
Thanks for writing this!
– user6546
Sep 11 at 10:48
1
1
Thanks for the expalantion!
– mattiav27
Sep 10 at 10:23
Thanks for the expalantion!
– mattiav27
Sep 10 at 10:23
Thanks for writing this!
– user6546
Sep 11 at 10:48
Thanks for writing this!
– user6546
Sep 11 at 10:48
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181597%2funderstanding-sow-and-reap-documentation%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
4
;
is the same asCompoundExpression
which returns the last argument. E.g.b; e
returnse
. What output did you expect?– Coolwater
Sep 10 at 8:20
It's ignored because it's followed by
;
. This has nothing to do withSow
/Reap
. It's not clear to me what you are asking / expecting.– Szabolcs
Sep 10 at 9:24
1
@mattiav27 Maybe you are actually looking for something like this:
Reap[ Sow[a, "list1"]; Sow[b, "list2"]; Sow[c, "list1"]; Sow[d, "list1"]; Sow[e, "list2"], _, Rule ]
? This uses tags to tell to which list a sown expression should be appended.– Henrik Schumacher
Sep 10 at 9:31