6.6

Assignment 18

home work!

Programming Language ISL

Due Date Tuesday 11/27 at 9pm

Purpose To practice generative recursion.

Expectations
  • You should submit a single .rkt file containing your responses to all exercises via the Handin Server. We accept NO email submissions.

  • You are only allowed to use one of the language specified at the top of this page: failure to do so will result in a 0.

  • You are expected to use pre-defined abstractions when stated and/or when appropriate.

  • Functions which recur but do not use structural recursion must be given a termination statement below the purpose statement. A termination statement is a comment that begins with "Termination:" and then briefly (1-2 sentences) explains why this function terminates.

Exercise 1 Design the function nat->string, which given a non-negative integer returns its string form. You may not use number->string, but you may use the function provided below.

; digit->string : [0, 9] -> String
; String representation of this digit
(check-expect (build-list 10 digit->string)
              (list "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"))
(define (digit->string d)
  (string (integer->char (+ 48 d))))

Exercise 2 Design the function string-split, which given a string to split and a non-empty delimiter splits the string by that delimiter. For example, (string-split "hello%%bob%%%i%%%%am%%jack" "%%") should return (list "hello" "bob" "%i" "" "am" "jack").