Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Do something unusual today. Pay a bill.


comp / comp.lang.lisp / Re: cloning elements in a list

SubjectAuthor
o Re: cloning elements in a listB. Pym

1
Subject: Re: cloning elements in a list
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 2 Sep 2024 03:39 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: cloning elements in a list
Date: Mon, 2 Sep 2024 03:39:39 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <vb3c1p$1r6la$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Mon, 02 Sep 2024 05:39:39 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="21169b4eafbc5b66ac48973ad23d07f7";
logging-data="1940138"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Hz8ZuBdKnFum2YrwdTClz"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:JsPweKwxTKuWMTl+4W5lxQGxuiY=
View all headers

> > How to write a lisp function which clones the top-level elements of a list
> L
> > (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

(define (stretch lst factor)
(append-map
(cut make-list factor <>)
lst))

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

1

rocksolid light 0.9.8
clearnet tor