FOREACH

Synopsis
FOREACH datalist templatelist
(FOREACH datalist1 datalist2 ... templatelist)
Description

Command that evaluates the templatelist repeatedly, once for each item in datalist. If more than one data list is given, each of them must be the same length. If the data inputs are words, then the template is evaluated once for each character.

In a template, the symbol ?REST represents the portion of the data input to the right of the member currently being used as the ? slot-filler. For example, if the data input is [A B C D E] and the template is being evaluated with ? replaced by B, then ?REST would be replaced by [C D E]. If multiple parallel slots are used, then (?REST 1) goes with ?1, etc.

In a template, the symbol # represents the position in the data input of the member currently being used as the ? slot-filler. For example, if the data input is [A B C D E] and the template is being evaluated with ? replaced by B, then # would be replaced by 2.

Example
FOREACH [a b c d] [PRINT (SENTENCE "index # "value ? "rest ?REST)]
index 1 value a rest b c d
index 2 value b rest c d
index 3 value c rest d
index 4 value d rest

SourceForge.net Logo