Up | Next | Prev | PrevTail | Tail |
The for each
form of the for
statement, designed for iteration down a list, is more
general in symbolic mode. Its syntax is:
for each
〈id:identifier⟩ (in
\(\ \mid \ \)on
) 〈lst:list⟩
(do
\(\ \mid \ \)collect
\(\ \mid \ \)join
\(\ \mid \ \)product
\(\ \mid \ \)sum
)〈exprn:S-expr⟩As in algebraic mode, if the keyword in
is used, iteration is on each element of the list.
With on
, iteration is on the whole list remaining at each point in the iteration. As a result,
we have the following equivalence between each form of for each
and the various
mapping functions in Lisp:
do | collect | join | |
in | mapc | mapcar | mapcan |
on | map | maplist | mapcon |
Example: To list each element of the list (a b c)
:
for each x in ’(a b c) collect list x;
Up | Next | Prev | PrevTail | Front |