Listloop enumerates and returns the elements of a list one by one.
In other words, at each step of the iteration, listloop takes a smaller chunk of the list, and returns its first element. The execution ends once the list is exhausted.
![]() | Listloop has one default input and one optional input :
|
Here, listloop enumerates a list and returns its items one by one.
At each step of the loop, EachtTime evaluates collect.
Collect stores the items of the list.
The default value of the " by " optional input is a cdr1 .
This means that, at each loop, listloop returns :
the first element of the list,
and then, the first element of the remaining chunk,
and so on.
In Lisp, this means that listloop returns successive cadrs1 .
"By" can be replaced by another function meant to return a smaller chunk of a list, such as : cddr 1 or nthcdr for instance.
It can be either a function box on "lambda" mode, or a function name.
![]() | If "by" is a cddr, Listloop returns
|
If "by" is an nthcdr, listloop returns
| ![]() |
Applying an irrelevant "by" argument to listloop may prevent the list from being exhausted. In this case, if no other iterator is present, the loop may go on for infinite iterations.
Elementary Lisp functions, allowing the access to one or more elements in a list. CAR and CDR are kernel functions upon which have been defined the rest of these functions.
Let the following list be : (A B C D).
CAR (A B C D) = A.
CDR (A B C D) = (B C D).
CADR (A B C D) = B. CADR means CAR of the CDR.
CDDR (A B C D) = (C D). CDDR means CDR of the CDR.
CADDR (A B C D) = C. CADDR means CAR of the CDDR.
NTHCDR (A B C D) = NTH CDR of the list – N must be specified as argument. NTHCDR 3 (A B C D) = (D).
And so on...