Hi I am trying to write an iterative lisp function that given a list A
returns a list with everything in A repeated twice consecutively. For
example A = [a,b,c] then the newlist = [a,a,b,b,c,c]. Any help would be
greatly appreciated. Thanks.
In article <············@ibm.net> temp <·······@ibm.net> writes:
>
> Hi I am trying to write an iterative lisp function that given a list A
> returns a list with everything in A repeated twice consecutively. For
> example A = [a,b,c] then the newlist = [a,a,b,b,c,c]. Any help would be
> greatly appreciated. Thanks.
Ok, you sucked me in. I'll do you a favor if you will do me one. I am
dying to find out if your source (you know what I mean) will accept
(defun double-em (list) (mapcan #'list list list))
so try with
(double-em '(a b c d)) => (A A B B C C D D)
Please report back.
--
William P. Vrotney - ·······@netcom.com
As a novice myself, here is what I came up with...
(defun double-element (x)
(list x x))
(defun double-list (x)
(cond ((null x) nil)
(t (append (double-element (first x)) (double-list (rest x))))))
It seems to do the job when tested with CLISP and FreeLisp.
Eric S. Ingram <········@cableinet.co.uk> wrote:
> As a novice myself, here is what I came up with...
> (defun double-element (x)
> (list x x))
> (defun double-list (x)
> (cond ((null x) nil)
> (t (append (double-element (first x)) (double-list (rest x))))))
> It seems to do the job when tested with CLISP and FreeLisp.
... try this:
(defun double-list (x)
(merge x x))
Adam Przybyla
Adam Przybyla wrote:
> ... try this:
> (defun double-list (x)
> (merge x x))
> Adam Przybyla
I tried that using FreeLisp and I got...
(double-list '(a b c))
Error: Call (#<Function MERGE 00112242> (A B C) (A B C)) has the wrong
number of arguments.
In article <·················@cableinet.co.uk>,
Eric S. Ingram <········@cableinet.co.uk> wrote:
>Adam Przybyla wrote:
>> ... try this:
>> (defun double-list (x)
>> (merge x x))
>> Adam Przybyla
>
>I tried that using FreeLisp and I got...
>
>(double-list '(a b c))
>
>Error: Call (#<Function MERGE 00112242> (A B C) (A B C)) has the wrong
>number of arguments.
He forgot the result-type a predicate parameters. See CLtL or the
HyperSpec for the correct syntax of MERGE (you don't want us doing *all*
your homework, do you?).
--
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
In article <················@cam-news-reader1.bbnplanet.com>, Barry
Margolin <······@bbnplanet.com> wrote:
> In article <·················@cableinet.co.uk>,
> Eric S. Ingram <········@cableinet.co.uk> wrote:
> >Adam Przybyla wrote:
> >> ... try this:
> >> (defun double-list (x)
> >> (merge x x))
> >> Adam Przybyla
> >
> >I tried that using FreeLisp and I got...
> >
> >(double-list '(a b c))
> >
> >Error: Call (#<Function MERGE 00112242> (A B C) (A B C)) has the wrong
> >number of arguments.
>
> He forgot the result-type a predicate parameters. See CLtL or the
> HyperSpec for the correct syntax of MERGE (you don't want us doing *all*
> your homework, do you?).
He also forgot that MERGE is DESTRUCTIVE and MERGEing shared structure is
clearly bogus, and may never terminate.
d
? (let ((x '(1 2 3)))
(merge 'list x x #'<))
> Break:
> While executing: #<Anonymous Function #x3E824A6>
> Type Command-/ to continue, Command-. to abort.
> If continued: Return from BREAK.
See the Restarts� menu item for further choices.
1 > (local 8)
#1=(1 . #1#)
1 > >
* temp <·······@ibm.net>
| Hi I am trying to write an iterative lisp function that given a list A
| returns a list with everything in A repeated twice consecutively. For
| example A = [a,b,c] then the newlist = [a,a,b,b,c,c]. Any help would be
| greatly appreciated. Thanks.
first, you have a pretty weird syntax for lists, but I guess you still
mean lists like (A B C) and (A A B B C C) not something else entirely.
however, back to your homework assignment: as you may have found out,
there are many ways to do what you want to do, but I have not yet seen
the simple _iterative_ solutions:
(loop for e in <list> collect e collect e)
I'm sure you are not allowed to use LOOP, but rewriting this to use DO or
DOLIST shouldn't be too hard.
#:Erik
--
religious cult update in light of new scientific discoveries:
"when we cannot go to the comet, the comet must come to us."
Erik Naggum wrote:
> * temp <·······@ibm.net>
> | Hi I am trying to write an iterative lisp function that given a list A
> | returns a list with everything in A repeated twice consecutively. For
> | example A = [a,b,c] then the newlist = [a,a,b,b,c,c]. Any help would be
> | greatly appreciated. Thanks.
>
> first, you have a pretty weird syntax for lists, but I guess you still
> mean lists like (A B C) and (A A B B C C) not something else entirely.
>
> however, back to your homework assignment: as you may have found out,
> there are many ways to do what you want to do, but I have not yet seen
> the simple _iterative_ solutions:
>
> (loop for e in <list> collect e collect e)
>
> I'm sure you are not allowed to use LOOP, but rewriting this to use DO or
> DOLIST shouldn't be too hard.
What about a "comp.lang.lisp.homework" - newsgroup?
Bye
Joe
Johannes Beck <····@www-info6.informatik.uni-wuerzburg.de> wrote:
> Erik Naggum wrote:
>> * temp <·······@ibm.net>
>> | Hi I am trying to write an iterative lisp function that given a list A
>> | returns a list with everything in A repeated twice consecutively. For
>> | example A = [a,b,c] then the newlist = [a,a,b,b,c,c]. Any help would be
>> | greatly appreciated. Thanks.
>>
>> first, you have a pretty weird syntax for lists, but I guess you still
>> mean lists like (A B C) and (A A B B C C) not something else entirely.
>>
>> however, back to your homework assignment: as you may have found out,
>> there are many ways to do what you want to do, but I have not yet seen
>> the simple _iterative_ solutions:
>>
>> (loop for e in <list> collect e collect e)
>>
>> I'm sure you are not allowed to use LOOP, but rewriting this to use DO or
>> DOLIST shouldn't be too hard.
> What about a "comp.lang.lisp.homework" - newsgroup?
(merge 'list (copy-list <list>) (copy-list <list>) #'eql)
Adam Przybyla