[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: cloning elements in a list

William James

7/23/2015 8:10:00 PM

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)

Gauche Scheme:

(use srfi-42 :only (append-ec))

(define (stretch items n)
(append-ec (: x items) (make-list n x)))

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

--
Under the disguise of liberalism, humanism, and democracy, Europeans have been
persuaded to commit racial suicide -- a race that has achieved so much and has
survived so much has been tricked into welcoming its own downfall and to take
active measures in order to become a stranger on its own soil.
www.kolumbus.fi/aquilon/moscowspeech2010.htm
1 Answer

Kaz Kylheku

7/23/2015 8:50:00 PM

0

On 2015-07-23, WJ <w_a_x_man@yahoo.com> wrote:
> Gauche Scheme:

Having invested this time, what are you actually *doing* with Gauche Scheme, in
terms of some kind of project?