newbie question
- From: "dvlfrnd" <iresjen@xxxxxxxxx>
- Date: 31 Dec 2005 12:04:23 -0800
hi there,
here's a newbie question
im not a programmer and lisp is the only language i've ever worked
with,
but somehow i love it and i wanna learn.
i was giving myself exercises and came up with this,pardon my
programming inefficency and please help.
say there's a list of even length
(a b c d e f ......)
how do i turn this into
((a b) (c d) (e f)....)
simply how do i couple the elements?
i first tried to write a function:
(defun couple-first-two (lst)
(list (first lst) (second lst)))
but couldn't find a way to apply it to the entire list.
i tried a recursive function,but it didnt give the output i wanted.
then i tried this
(defun pair-add-element (n lst)
(mapcar #'(lambda (x) (list n x)) lst))
if i could split the list into two,
where the original is (a b c d e f)
to
(a c e) and (b d f)
i could mapcar these two new lists using pair-add-element function
above
and return this
((a b) (c d) (e f))
so the i have two questions
1- how do i split a list into two, taking even'th and odd'th elemtns
into separate lists
2- how do i achieve this final goal of (a b c d e f) --->> ((a b) (c d)
(e f)) in an efficient,proper code
how's my approach?? is it too silly, i know i have tons to learn about
programming, please show me a way to solve this, including the code and
the approach,design etc...
thank you very much
and happy new year
.
- Follow-Ups:
- Re: newbie question
- From: Frank Buss
- Re: newbie question
- From: Coby Beck
- Re: newbie question
- From: Kenny Tilton
- Re: newbie question
- From: Frank Buss
- Re: newbie question
- From: Frode Vatvedt Fjeld
- Re: newbie question
- From: JP Massar
- Re: newbie question
- Prev by Date: Re: Trade-off, option, choice.
- Next by Date: Re: newbie question
- Previous by thread: Trade-off, option, choice.
- Next by thread: Re: newbie question
- Index(es):
Relevant Pages
|