Please use scheme programming with Dr Racket Create a recurs
Please use scheme programming with Dr. Racket
Create a recursive procedure called (alternate lst1 lst2 lst3) that returns a list with alternative values from the 3 given list. Use comments to indicate in the code the four steps of the fantastic approach. Assume that all 3 lists have the same length. Hint: (append lst1 lst2 lst3) returns the appended list.
Test case: (alternate ‘(1 2 3) ‘(a b c) ‘(m n o)) should give \'(1 a m 2 b n 3 c o).
Solution
(define (alternate lst1 lst2 lst3) (if (or (null? lst1) (null? lst2) (null? lst3)) \'() ;stopping condition (cons (car lst1) (cons (car lst2) ;step 4 (cons (car lst3) (alternate (cdr lst1)(cdr lst2)(cdr lst3)))))));size n problem