asdfghjkl
asdfghjkl

Reputation: 393

zipping two lists together in racket

I am trying to write a function called zip that accepts two lists as parameters and and returns a single list whose elements are taken alternatively from the original lists

ex. (zip '(a b c) '(x y z)) should evaluate to (a x b y c z)

Upvotes: 0

Views: 1418

Answers (1)

C. K. Young
C. K. Young

Reputation: 223003

Skeleton solution:

(define (zip l1 l2)
  (cond ((null? l1) l2)
        ((null? l2) l1)
        (else (cons ??? (cons ??? (zip ??? ???))))))

Fill in the ??? yourself. :-)

Upvotes: 4

Related Questions