From: temp
Subject: Help
Date: 
Message-ID: <350DE565.732@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.

From: William Paul Vrotney
Subject: Re: Help
Date: 
Message-ID: <vrotneyEpy610.5w5@netcom.com>
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
From: Eric S. Ingram
Subject: Re: Help
Date: 
Message-ID: <350F8E5F.B57EA933@cableinet.co.uk>
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.
From: Adam Przybyla
Subject: Re: Help
Date: 
Message-ID: <6ercba$qmv$1@info.nask.pl>
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
From: Eric S. Ingram
Subject: Re: Help
Date: 
Message-ID: <35114759.C6B04DB5@cableinet.co.uk>
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.
From: Barry Margolin
Subject: Re: Help
Date: 
Message-ID: <1kcQ.3$fl.313253@cam-news-reader1.bbnplanet.com>
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.
From: David D. Smith
Subject: Re: Help
Date: 
Message-ID: <dds-2003980959120001@p74.bit-net.com>
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 > >
From: Erik Naggum
Subject: Re: Help
Date: 
Message-ID: <3099401333254064@naggum.no>
* 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."
From: Johannes Beck
Subject: Re: Help
Date: 
Message-ID: <3518DEC2.BAFF0327@www-info6.informatik.uni-wuerzburg.de>
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
From: Adam Przybyla
Subject: Re: Help
Date: 
Message-ID: <6fb1bu$2fi$1@info.nask.pl>
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