Lecture overview -- Keyboard shortcut: 'u'  Previous page: Example of recursion: <span>number-interval</span> -- Keyboard shortcut: 'p'  Next page: Examples with recursion: <span>string-of-char-list?</span> -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 2 - Page 6 : 35
Programming Paradigms
Recursion and Higher-order Functions
Examples of recursion: string-merge

The function string-merge zips two lists of strings to a single string. The lists are not necessarily of equal lengths

(define (string-merge str-list-1 str-list-2)
 (cond ((null? str-list-1) (apply string-append str-list-2))
       ((null? str-list-2) (apply string-append str-list-1))
       (else (string-append
              (car str-list-1) (car str-list-2)
              (string-merge (cdr str-list-1) (cdr str-list-2))))))

The recursive function string-merge. Notice that this function is a general recursive function. The recursive call, emphasized above, is not in a tail position, because of the embedding in string-append.

c:/Users/Kurt/Teaching-material/Pp-Scheme-17/notes/includes/string-merge-iter.scmA tail recursive version of string-merge.


Go to exerciseMore about string-merge