6.7

Week 9 Set c

home work!

Programming Language ISL

Due Date Fri at 9pm (Week 9)

Purpose To practice the design of functions on mutually recursive data definitions

Finger Exercises

Exercise 1 From HtDP, 326 and 327.

Graded Exercises

Exercise 2 Design the function find-path. Its inputs are a Symbol and a symbolic S-expression:
; An Sexpr is one of:
;  Symbol
;  Lexpr
; 
; An  Lexpr is one of:
;  '()
;  (cons Sexpr Lexpr)
If the Symbol occurs in the Sexpr, the function produces a Path:

; A Path is [List-of N], that is, a list of natural numbers.

Otherwise it is #false.

Specifically, the path that find-path produces is a list of indexes that takes you to the first (leftmost) occurrence of the given Symbol in the given Sexpr. Because this last part is somewhat ambiguous, let’s refine it. If the given Symbol and Sexpr are equal, the path is '(). Otherwise the path starts with a 0-based index that points to the leftmost Sexpr in the list that contains the Symbol. Thus the result for '(b c a d e f) and 'a is '(2).

Note This problem might be the most complicated problem this semester. If you follow the design recipe systematically, you are most certainly going to find a concise solution. If you do not follow it or only partially, it is unlikely that you find a solution.