newbie question



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

.



Relevant Pages

  • Re: newbie question
    ... John wrote: ... >> programming inefficency and please help. ... >> into separate lists ... > (defun pair (lst) ...
    (comp.lang.lisp)
  • Re: newbie question
    ... > here's a newbie question ... > programming inefficency and please help. ... > (defun pair-add-element (n lst) ... > i could mapcar these two new lists using pair-add-element function ...
    (comp.lang.lisp)
  • Welcome to comp.lang.c!
    ... and posting in this newsgroup. ... Languages and Programming ... This is a very busy group, so these requests are designed to make it as ... Variable-Length Argument Lists http://www.eskimo.com/~scs/C-faq/s15.html ...
    (comp.lang.c)
  • Welcome to comp.lang.c!
    ... and posting in this newsgroup. ... Languages and Programming ... This is a very busy group, so these requests are designed to make it as ... Variable-Length Argument Lists http://www.eskimo.com/~scs/C-faq/s15.html ...
    (comp.lang.c)
  • Welcome to comp.lang.c!
    ... and posting in this newsgroup. ... Languages and Programming ... This is a very busy group, so these requests are designed to make it as ... Variable-Length Argument Lists http://www.eskimo.com/~scs/C-faq/s15.html ...
    (comp.lang.c)