Exercises in this lecture   Go to the notes, in which this exercise belongs -- Keyboard shortcut: 'u'   Alphabetic index   Course home   

Exercise solution:
More about string-merge


Here is a solution for the non-tail recursive variant of string-merge:

(define (string-merge str-list-1 str-list-2)
 (cond ((and (null? str-list-1) (not (null? str-list-2))) 
             (string-append (car str-list-2) (string-merge '() (cdr str-list-2))))
       ((and (not (null? str-list-1)) (null? str-list-2))
             (string-append (car str-list-1) (string-merge (cdr str-list-1) '())))
       ((and (null? str-list-1) (null? str-list-2)) "")
       (else (string-append
              (car str-list-1) (car str-list-2)
              (string-merge (cdr str-list-1) (cdr str-list-2))))))