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 - vro...@netcom.com
(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
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, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
> In article <35114759...@cableinet.co.uk>,
> Eric S. Ingram <e.in...@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 > >
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."
What about a "comp.lang.lisp.homework" - newsgroup?
Bye
Joe
(merge 'list (copy-list <list>) (copy-list <list>) #'eql)
Adam Przybyla