![]() |
CS 341 - Survey of Programming Languages
Homework #3 |
Note: This work is to be done in pairs. Each pair will submit one assignment. Although you may divide the work, both team members should be able to present/describe their partner's work upon request. All written exercises are to be done in a README file. All Scheme code is to be done in a file hw3.scm. All exercises should be clearly labeled or commented.
EOPL Exercises
Test path for all numbers in the given test tree below. This is easily accomplished using your definition of flatten and the expressions:
(define test-tree '(14 (7 () (12 () ()))
(26 (20 (17 () ())
())
(31 () ()))))
test-tree
(flatten test-tree)
(map (lambda (n) (path n test-tree)) (flatten test-tree))
Call the second sort sort-pred. You may implement any
recursive sorting method with worst-case time-complexity O(n2).
(Insertion sort can be implemented recursively.) You may wish to do part 3
first and use that code for part 2 (a special case).
Hint: Read in the Scheme reference section 6.3.2 about memq, memv, member, and append. You may wish to create a "helper" or "auxiliary" function that enables you to keep track of the variables currently bound in any subexpression.
Perform at least these tests:
(free-vars '((lambda (x) x) y))
=> (y)
(bound-vars '((lambda (x) x) y))
=> (x)
(free-vars '((lambda (x) y) (lambda (a) (lambda (b) (a b)))))
=> (y)
(bound-vars '((lambda (x) y) (lambda (a) (lambda (b) (a b)))))
=> (a b)
For each exercise, you're required to include in your file the test examples given in the text. In addition, you're encouraged to develop a good test suite beyond the limited text examples.