Refactor foreach into mapping + body.

The mapping part of 'foreach x as y { body }' might be more generally useful, and we certainly need to refactor if we are to switch the order to 'foreach y <- x { body }'.
More assertions.
Rearrange foreach header.

Instead of "foreach list_of_things as name", say "foreach name in list_of_things".