Warning: the material in this lab is quite challenging. It is highly recommended that you work with a partner.

So far, all our examples of recursion have been command blocks, whose scripts have a structure like this:

recursive command pattern

There can be any number of recursive calls interspersed with other commands in the script.

Reporters are slightly trickier, because a reporter can only report one value. So you can't do this:

bad (multi-report) recursive reporter pattern

(In fact, Snap! won't let you stack report blocks; since report ends the script, there is no connection tab below the block and you can't put anything directly below it. Optional exercise for hotshots: How did we make that picture?)

Instead, most of the time a recursive reporter call will be inside a combiner that attaches the result of the recursive call to some other value:

correct recursive reporter pattern with combiner

The combiner can be an arithmetic operator such as + or ×:

factorial

or a text string operator such as join or join words:

list->sentence

or a list operator such as append or in front of:

plurals

Note: Occasionally, the recursive call does appear directly inside the report:

piglatin

(Wikipedia article on pig latin. Our block only accounts for the first rule.)

But most of the time, you won't go wrong if you start by thinking about what combining block to use.

☞ Don't go on until you understand what those four example scripts do, and how they do it.