Sow

Sow[e]

specifies that e should be collected by the nearest enclosing Reap.

Sow[e,tag]

specifies that e should be collected by the nearest enclosing Reap whose pattern matches tag.

Sow[e,{tag1,tag2,}]

specifies that e should be collected once for each pattern that matches a tagi.

Details

  • Sow[e,] returns e.
  • By having several identical tagi, a single expression can be made to appear multiple times in a list returned by Reap.
  • Sow[e] is equivalent to Sow[e,None].
  • Sow[e,{{tag}}] sows an expression with tag {tag}.

Examples

open allclose all

Basic Examples  (4)

Evaluate a sequence of expressions, "sowing" some to be collected by Reap:

Compute a sum, "sowing" i^2 at each step:

Make separate lists for expressions "sown" with different tags:

Reap only expressions "sown" with tag x:

Scope  (5)

Sow can be used anywhere in a computation:

It still works inside a function:

A single expression can be "sown" with multiple tags:

If a single tag is repeated, the expression is sown repeatedly:

A pattern in Reap can be used to specify which tags to collect:

The default is the pattern _, so that everything is collected:

Tags can have any form; here they are True and False:

Applications  (3)

Make a list of all the steps taken in evaluating FindRoot:

Evaluate an iterated map, keeping iterates that are below 1/100:

Find equivalence classes with respect to the value of mod 10:

Properties & Relations  (2)

Sow[x] returns x, "sowing" it as a side effect:

Expressions sown are reaped by the innermost enclosing Reap:

Wolfram Research (2003), Sow, Wolfram Language function, https://reference.wolfram.com/language/ref/Sow.html.

Text

Wolfram Research (2003), Sow, Wolfram Language function, https://reference.wolfram.com/language/ref/Sow.html.

CMS

Wolfram Language. 2003. "Sow." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Sow.html.

APA

Wolfram Language. (2003). Sow. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Sow.html

BibTeX

@misc{reference.wolfram_2024_sow, author="Wolfram Research", title="{Sow}", year="2003", howpublished="\url{https://reference.wolfram.com/language/ref/Sow.html}", note=[Accessed: 09-October-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_sow, organization={Wolfram Research}, title={Sow}, year={2003}, url={https://reference.wolfram.com/language/ref/Sow.html}, note=[Accessed: 09-October-2024 ]}