Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cloning elements in a list

12 views
Skip to first unread message

Robert L.

unread,
Mar 12, 2018, 7:42:24 PM3/12/18
to
Coby Beck wrote:

> > How to write a lisp function which clones the top-level elements of a list
> > (first arguement) n ( second argument) times. for eg. (clone 'A B C) 4 )
> > produces ( AAAABBBBCCCC)
>
> To rewrite your question to what I *think* you mean:
> (clone '(A B C) 4 )
> => (A A A A B B B B C C C C)
>
> try this:
> CL-USER 143 > (defun stretch (list factor)
> (loop for elt in list
> nconc (make-list factor :initial-element elt)))
> STRETCH
>
> CL-USER 144 > (stretch '(a b c) 4)
> (A A A A B B B B C C C C)

(require srfi/42) ; list-ec

(define (stretch the-list n)
(list-ec (:list x the-list) (:range _ n) x))

(stretch '(a b c) 4)
===>
'(a a a a b b b b c c c c)

--
Jewish drug dealers, child porn pushers, and slave traders are free
from prosecution in Israel. Israel does not consider these to be
crimes ... so long as the victims are non-Jews.
http://archive.org/details/nolies
0 new messages