The base foreach

The base form of foreach has the following form:

		 		 foreach($E_1$ in $D_1$, $\ldots$, $E_n$ in $D_n$, $LocalVars$,$Goal$) 

where $E_i$ is a pattern which is normally a variable but can be any term, and $D_i$ a collection, $LocalVars$, which is optional, is a list of variables in $Goal$ that are local to each iteration, and $Goal$ is a callable term. All variables in $E_i$'s are local variables. The foreach call means that for each combination of values $E_1 \in D_1$, $\ldots$, $E_n \in D_n$, the instance $Goal$ is executed after local variables are renamed. The call fails if any of the instances fails. Any variable, including the anonymous variable '_', that occurs in $Goal$ but is not in any $E_i$ or $LocalVars$ is shared by all iterations.

A collection takes one of the following forms:



Subsections
Neng-Fa Zhou 2012-01-03