Frode Vatvedt Fjeld wrote:
> > 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)....)
>
> The mapping idiom doesn't work so well here, since that's all about
> transforming each element individually, whereas here you process
> elements two by two (or the list as such in steps of two).
>
> I think this is the most natural solution in Common Lisp:
>
> (loop for (x y) on list by #'cddr collect (list x y))
OCaml:
let list = ["a";"b";"c";"d"];;
let rec g=function x::y::z->(x,y)::g z | _->[]
in g list;;
[("a", "b"); ("c", "d")]
--
[A]n unholy alliance of leftists, capitalists, and Zionist supremacists has
schemed to promote immigration and miscegenation with the deliberate aim of
breeding us out of existence in our own homelands.... [T]he real aim stays the
same: the biggest genocide in human history.... --- Nick Griffin
(
https://www.youtube.com/watch?v=K0hD7IffTJs)