#lang racket ; This example, related to a02, illustrates a way to convert triples containing ; lists of strings into triples containing just strings. (require htdp/testing) ; combine-strings combines a list of strings into one string, interposing ; a blank between successive strings. (define (combine-strings L) (cond ((null? L) "") ; Empty list converts to empty string. ((null? (rest L)) (first L)) ; No blanks are inserted for a list of one. (else (string-append (first L) " " ; The interposed blank. (combine-strings (rest L)))))) ; convert-triple converts a triple consisting of two lists of strings and ; a third item into two strings and the third item, using combine-strings. (define (convert-triple Triple) (list (combine-strings (first Triple)) (combine-strings (second Triple)) (third Triple))) ; convert-triples maps convert-triple over a list of triples. (define (convert-triples Triples) (map convert-triple Triples)) ; example (check-expect (convert-triples '( (("first" "of" "several") ("the") 0) (("of" "several") ("the" "first") 1) (("several") ("the" "first" "of") 2) (("the" "first" "of" "several") () 3) )) '( ("first of several" "the" 0) ("of several" "the first" 1) ("several" "the first of" 2) ("the first of several" "" 3) )) (generate-report)