Hi.
Have you looked the CLHS for list?
s.
On Mon, 06 May 2002 18:02:30 -0400,
TejimaNoHimitsu <····@test.com> wrote:
> I'm having a tough time with a particular part of a program I have to
> write. Please look at the following snippit of code:
>
>
> (mapcar #'(lambda (y)
> (cond ((equal (car y) (elt x (+ 1 (position '* x))))
> (add-l (list j (car y) (cddr y)) j)))) text
> )
>
>
> add-l is another function I defined that does stuff, but that's not
> important. The part that bothers me is the (cddr y) part because it
> keeps returning a list when in fact I want each individual element in
> that list. For example, the above code currently yields
>
> ((2 Fred (eats cake)))
>
> whereas I want it to yield
>
> ((2 Fred eats cake)) .............. but I dunno how =/
>
>
> I would access each element in the (cddr y) separately, but the number
> of elements could be anywhere from 1 to infinity (theoretically).
>
> Anyone know of a way I might be able to do this? Thanks!
>
> - T
TejimaNoHimitsu <····@test.com> writes:
> Yeah, I've looked at the CLHS for list and that didn't help any. If
> the (cddr y) was 1 element, that wouldn't be a problem. As it is, it
> could be 1 to 1000000000 elements and list* only append one item to a
> list. While that's a nice function, I'm not sure how that could help
> solve my problem as I need to convert a list to an un-list.....
Think through the chapter on CONS and LIST in your basic lisp textbook
(you do have one, right?) once more. Then evaluate the following
expressions one at a time, and try to make sense of them.
(cons 'a 'b) ;; See definition of dotted cons
(cons 'a '(b c d)) ;; Again, see definition of dotted cons.
;; This is where you should go AHA!
(list* 'a '(b c d)) ;; What is the last arg to list* here?
;; Think "hooking onto a chain".
(list 'a '(b c d)) ;; Think "creating new links in a chain".
(cons 'a '((b c d)))
I believe you have a basic misunderstanding to correct, so keep at
this until you go AHA! Draw boxes and arrows if that helps.
--
H�kon Alstadheim, hjemmepappa.