Next: Generalized Drivers, Previous: Numerical Iteration, Up: Drivers
There are a number of clauses for iterating over sequences. In all of
them, the argument following for
may be a list instead of a
symbol, in which case destructuring is performed. See
Destructuring.
&optional
by
step-functionvar is set to successive elements of list. step-function, which defaults to
cdr
, is used to obtain the next sublist.
&optional
by
step-functionvar is set to successive sublists of list. step-function (default
cdr
) is used as infor... in
.
These two clauses use atom
to test for the end of a list.
Hence, given a list whose final cdr
is not nil
, they
will silently ignore the last cdr
. Other choices are
endp
, which would signal an error, and null
, which would
probably result in an error somewhere else. If you wish to use an
end-test other than atom
, set the variable
iterate::*list-end-test*
to the name of the desired function.
&sequence
var takes on successive elements from vector. The vector's fill-pointer is observed. Here and in subsequent clauses, the
&sequence
keywords includewith-index
, which takes a symbol as argument and uses it for the index variable instead of an internally generated symbol. The other&sequence
keywords behave as in numerical iteration, except that the default iteration bounds are the bounds of the vector. E.g. in(for i in-vector v downto 3)
,i
will start off being bound to the last element inv
, and will be set to preceding elements down to and including the element with index 3.
&sequence
This uses Common Lisp's generalized sequence functions,
elt
andlength
, to obtain elements and determine the length of seq. Hence it will work for any sequence, including lists, and will observe the fill-pointers of vectors.
&sequence
&sequence
&sequence
var is set to successive indices of the sequence. These clauses avoid the overhead of accessing the sequence elements for those applications where they do not need to be examined, or are examined rarely. They admit all the optional keywords of the other sequence drivers except the (redundant)
with-index
keyword.
key and value, which must appear as shown in a list and may be destructuring templates, are set to the keys and values of table. If key is
nil
, then the hashtable's keys will be ignored; similarly for value. The order in which elements of table will be retrieved is unpredictable.
&optional
external-only
extIterates over all the symbols in package, or over only the external symbols if ext is specified and non-
nil
. ext is not evaluated. The same symbol may appear more than once.
&optional
having-access
symbol-typesIterates over all the symbols from the list of packages denoted by the descriptor packages and having accessibility (or visibility) given by symbol-types. This defaults to the list
(:external :internal :inherited)
and is not evaluated. var must be a list of up to three variables: in each iteration, these will be set to a symbol, its access-type and package (as perwith-package-iterator
in ANSI CL). The same symbol may appear more than once.
&optional
using
readerOpens the file name (which may be a string or pathname) for input, and iterates over its contents. reader defaults to
read
, so by default var will be bound to the successive forms in the file. Theiterate
body is wrapped in anunwind-protect
to ensure that the file is closed no matter how theiterate
is exited.