From Newsgroup: comp.lang.lisp
B. Pym wrote:
* (with-collectors (foo)
(loop for pos upfrom 1
for l in '((a b c) (one two three) (you and me) (girl))
do (collect pos :into foo)
do (loop for sym in l
do (collect pos :into foo))
finally (return foo)))
(1 A B C 2 ONE TWO THREE 3 YOU AND ME 4 GIRL)
;;; Or....
* (loop for pos upfrom 1
for l in '((a b c) (one two three) (you and me) (girl))
collect pos
append l)
(1 A B C 2 ONE TWO THREE 3 YOU AND ME 4 GIRL)
Gauche Scheme
(append-map
cons
(lrange 1) ;; Infinite but lazy.
'((a b c) (one two three) (you and me) (girl)))
===>
(1 a b c 2 one two three 3 you and me 4 girl)
Another way:
(concatenate (map-with-index cons
'((a b c) (one two three) (you and me) (girl))))
===>
(0 a b c 1 one two three 2 you and me 3 girl)
--- Synchronet 3.21d-Linux NewsLink 1.2