Beginner's Question on an exercise from Graham's ACL
From: A. Michael Perry (amperry_at_provide.net)
Date: 08/24/04
- Next message: Christophe Rhodes: "Re: A "Lisp Machine" and cons cells"
- Previous message: Ian J Cottee: "Re: tools for creating documentation for lisp?"
- Next in thread: Pascal Bourguignon: "Re: Beginner's Question on an exercise from Graham's ACL"
- Reply: Pascal Bourguignon: "Re: Beginner's Question on an exercise from Graham's ACL"
- Reply: Joost Kremers: "Re: Beginner's Question on an exercise from Graham's ACL"
- Reply: Marco Baringer: "Re: Beginner's Question on an exercise from Graham's ACL"
- Maybe reply: Tayssir John Gabbour: "Re: Beginner's Question on an exercise from Graham's ACL"
- Reply: Tassilo Horn: "Re: Beginner's Question on an exercise from Graham's ACL"
- Reply: neo88: "Re: Beginner's Question on an exercise from Graham's ACL"
- Maybe reply: Tayssir John Gabbour: "Re: Beginner's Question on an exercise from Graham's ACL"
- Reply: Wade Humeniuk: "Re: Beginner's Question on an exercise from Graham's ACL"
- Reply: John Thingstad: "Re: Beginner's Question on an exercise from Graham's ACL"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 24 Aug 2004 06:57:05 GMT
Hello folks,
I'm trying to get through Graham's ANSI Common Lisp, and I've gotten
myself hung up on an exercise: chapter 3, ex. 2. "Write a version of union
that preserves the order of the elements in the original lists:
>(new-union '(a b c) '(b a d))
(A B C D)"
I've come up with something that gets close, but not quite. (Strangely,
the concept of recursion doesn't seem so hard, but operations on lists
seem to be throwing me.)
(defun unite (ls1 ls2)
(if (null ls2)
ls1
(if (member (car ls2) ls1)
(unite ls1 (cdr ls2))
(unite (list ls1 (car ls2)) (cdr ls2)))))
--with this, (unite '(a b c) '(b a d)) generates the following:
((A B C) D)
If I substitute "append" for list in the last line above, I get a list
like so:
(A B C . D)
And substituting cons gets everything in one list, but in the wrong order.
Any ideas on what I'm getting wrong here?
- Next message: Christophe Rhodes: "Re: A "Lisp Machine" and cons cells"
- Previous message: Ian J Cottee: "Re: tools for creating documentation for lisp?"
- Next in thread: Pascal Bourguignon: "Re: Beginner's Question on an exercise from Graham's ACL"
- Reply: Pascal Bourguignon: "Re: Beginner's Question on an exercise from Graham's ACL"
- Reply: Joost Kremers: "Re: Beginner's Question on an exercise from Graham's ACL"
- Reply: Marco Baringer: "Re: Beginner's Question on an exercise from Graham's ACL"
- Maybe reply: Tayssir John Gabbour: "Re: Beginner's Question on an exercise from Graham's ACL"
- Reply: Tassilo Horn: "Re: Beginner's Question on an exercise from Graham's ACL"
- Reply: neo88: "Re: Beginner's Question on an exercise from Graham's ACL"
- Maybe reply: Tayssir John Gabbour: "Re: Beginner's Question on an exercise from Graham's ACL"
- Reply: Wade Humeniuk: "Re: Beginner's Question on an exercise from Graham's ACL"
- Reply: John Thingstad: "Re: Beginner's Question on an exercise from Graham's ACL"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|