a3q1 - ;;(combine-neighbour-strings...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname a3q1) (read-case- sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) ;;cs116 Assignment 3 Question 1 ;;r46wang 20319247 ;;combine-neighbours-strings: (listof string) -> (listof string) ;; this function consumes a list of strings and produces a list of combined strings. Thus the list of strings produced will be half or half + 1 (for odd length) of the original list of strings. ;;Examples: ;;(combine-neighbour-strings empty) => empty ;;(combine-neighbour-strings '("abc")) => '("abc") ;;(combine-neighbour-strings '("abc" "def")) => '("abcdef")
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ;;(combine-neighbour-strings '("abc" "123" "def")) => '("abc123" "def") ;;(combine-neighbour-strings '("abc" "123" "def" "456")) => '("abc123" "def456") (define (combine-neighbours-strings lst) (cond [(or(empty? lst)(empty?(rest lst))) lst] [else (cons (string-append (first lst)(second lst)) (combine-neighbours-strings (rest (rest lst))))])) ;;Tests: (check-expect (combine-neighbours-strings empty) empty) (check-expect (combine-neighbours-strings '("abc")) '("abc")) (check-expect (combine-neighbours-strings '("abc" "def")) '("abcdef")) (check-expect (combine-neighbours-strings '("abc" "123" "def")) '("abc123" "def")) (check-expect (combine-neighbours-strings '("abc" "123" "def" "456")) '("abc123" "def456"))...
View Full Document

Ask a homework question - tutors are online