Next: ’for-as-equals-then’, Previous: ’for-as-in-list’, Up: Iteration Control [Contents][Index]
This is the third of seven ‘for/as’ syntaxes
for var [type-spec] on expr1 [by step-fun] as var [type-spec] on expr1 [by step-fun]
This construct iterates over the contents of a list (using the successive tails of the list each iteration).
endp.
var
is bound to the successive tails of the list expr1
.
step-fun
is called on the list
and is expected to produce a successor list; the default value for step-fun
is the cdr
function.
;;; Collect successive tails of a list. (loop for sublist on '(a b c d) collect sublist)
;;; Print a list by using destructuring with the loop keyword ON. (loop for (item) on '(1 2 3) do (print item)) ;Prints 3 lines