Programming Languages (CSC-302 98S)

[Instructions] [Search] [Current] [Changes] [Syllabus] [Handouts] [Outlines] [Assignments]

Makeup Assignment for Assignment Five: Functional Programming in Scheme

Assigned: Monday, April 27, 1998
Due: 11am, Monday, May 4, 1998

This is an optional assignment. If you complete this assignment, I will average your grade on this assignment with your grade on assignment five. Note that my grading will be particularly strict on this makeup assignment.

1. Permutations

Define and test a predicate, (permutation? L1 L2), that holds if and only if L2 is a permutation of L1.

2. Heap Sort

Define and test a function, (heapsort lst), that sorts a list using the heap sort procedure. Recall that to heap sort a list, you put all of the elements of a list into a heap and then remove the remaining smallest element one at a time.

You will need to figure out an appropriate way to represent and manipulate heaps so that (insert elt heap) and (removesmallest heap) are logarithmic time operations.

3. Manipulating Encapsulated Lists

Define and test a function, (encap-map fun lst) that creates the encapsulated list that results from mapping a function onto an encapsulated list. You should ensure that the function is not applied to any member of the list until that element of the result list is demanded.

4. Converting to continuation-passing style

Define and test a function, (to-cps exp) that converts a Scheme arithmetic expression to continuation-passing style using the operations from the notes on assignment five. You need not worry about using the current continuation here; rather, create a lambda expression that takes the current continuation and failure continuations as parameters.

For example, given (+ 2 (* 4 5)), your function should produce something like

(lambda (cont failcont)
  (cmult 4 5 failcont (lambda (res)
  (cadd 2 res) failcont cont)))

Similarly, given (* (+ 2 3) (+ 4 5)), your function should produce something like

(lambda (cont failcont)
  (cadd 2 3 failcont (lambda (res1)
  (cadd 4 5 failcont (lambda (res2)
  (cmult res1 rest failcont cont))))))

Given a single value, like 2, your function should produce something like

(lambda (cont failcont)
  (cont 2))

Your result should be in a form that can be printed out. You don't need to worry about evaluation (although it shouldn't be hard if you produce correct expressions).

You should handle the following types of expressions:

[Instructions] [Search] [Current] [Changes] [Syllabus] [Handouts] [Outlines] [Assignments]

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

Source text last modified Mon Apr 27 07:55:57 1998.

This page generated on Mon Apr 27 08:00:46 1998 by SiteWeaver.

Contact our webmaster at