fork download
  1. ; alternating lists
  2.  
  3. (define (alternate . xss)
  4. (let loop ((xss xss) (zs (list)))
  5. (display xss) (display " ")
  6. (display zs) (newline)
  7. (cond ((null? xss) (reverse zs))
  8. ((null? (car xss)) (loop (cdr xss) zs))
  9. (else (loop (append (cdr xss) (list (cdar xss)))
  10. (cons (caar xss) zs))))))
  11.  
  12. (display (alternate '(1 2 3 4 5) '(a b c) '(w x y z)))
Success #stdin #stdout 0.02s 50224KB
stdin
Standard input is empty
stdout
((1 2 3 4 5) (a b c) (w x y z)) ()
((a b c) (w x y z) (2 3 4 5)) (1)
((w x y z) (2 3 4 5) (b c)) (a 1)
((2 3 4 5) (b c) (x y z)) (w a 1)
((b c) (x y z) (3 4 5)) (2 w a 1)
((x y z) (3 4 5) (c)) (b 2 w a 1)
((3 4 5) (c) (y z)) (x b 2 w a 1)
((c) (y z) (4 5)) (3 x b 2 w a 1)
((y z) (4 5) ()) (c 3 x b 2 w a 1)
((4 5) () (z)) (y c 3 x b 2 w a 1)
(() (z) (5)) (4 y c 3 x b 2 w a 1)
((z) (5)) (4 y c 3 x b 2 w a 1)
((5) ()) (z 4 y c 3 x b 2 w a 1)
(() ()) (5 z 4 y c 3 x b 2 w a 1)
(()) (5 z 4 y c 3 x b 2 w a 1)
() (5 z 4 y c 3 x b 2 w a 1)
(1 a w 2 b x 3 c y 4 z 5)