PasteRack.org
Paste # 95154
2025-09-29 16:49:48

Fork as a new paste.

Paste viewed 233 times.


Embed:

  1. #lang racket
  2.  
  3. (define (interleave l1 l2)
  4.   (match* (l1 l2)
  5.           [((list) (list)) (list)]
  6. [((cons h1 t1) (list)) l1]
  7. [((list) (cons h2 t2)) l2]
  8. [((cons h1 t1) (cons h2 t2)) (cons h1 (cons h2 (interleave t1 t2)))]))
  9.  
  10. (define list1 (list 1 2 3))
  11. (define list2 (list 4 5 6))
  12. (interleave list1 list2)

=>

'(1 4 2 5 3 6)