how to design a function that merge two lists into one list. the first element of first list will be the first element of the new list and the first element of the second list will be the second element of the new list (a,b,c,d,e,f) (g,h,i) will be (a,g,b,h,c,i,d,e,f,)
Here is a purely functional and recursive implementation in R6RS
(define (merge l1 l2)
(if (null? l1) l2
(if (null? l2) l1
(cons (car l1) (cons (car l2) (merge (cdr l1) (cdr l2)))))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With