Reputation: 1
(defun ppl (list)
(loop for x in list
collect (cons x '(ppl))))
(ppl '(1 2 3))
=> ((1 ppl) (2 ppl) (3 ppl))
While still inside ppl
, how do I remove the parenthesis so that the result becomes
=> (1 ppl 2 ppl 3 ppl)
I understand that my code fundamentally creates a list of sublists. Could use some help on flattening out the list. Perhaps if I could in some way get the list that collect returns?
Upvotes: 0
Views: 112
Reputation: 60014
(defun ppl (list)
(loop for x in list
nconc (list x 'ppl)))
(ppl '(1 2 3))
==> (1 PPL 2 PPL 3 PPL)
Please note that I replaced (cons x '(ppl))
with (list x 'ppl))
to avoid possible reuse of literal (ppl)
which nconc
could turn into circular lists. If you insist on having quoted literals in your code (bad idea!), use append
instead of nconc
.
Upvotes: 2