Functional Problem Solving (CSC 151 2015F) : EBoards

CSC151.01 2015F, Class 52: An Introduction to Sorting


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit Opportunities

Academic

Peer Support

Regular Peer Support

Misc.

Upcoming Peer Support

Other Good Things (No Extra Credit)

Questions

Why does the following code make DrRacket upset?

    (define read-file
      (lambda (file-name)
         (let ([line (read-line (open-input-file file-name))])
           (if (eof-object? line)
               (close-input-port (open-input-file file-name))
               (cons line (read-file file-name))))))

Because you are not being careful in your recursion, it keeps opening ports again and again and again and always reads the first line, so it's even going to recurse forever.

How can I fix it?

Maybe you should look at the sample code from the files lab for good ideas.

I can't figure out how to call binary-search on problem 6.

You shouldn't. You should write a new procedure using the ideas of binary search (and perhaps even some of the code).

How can we make fewer cons calls on problem 7?

Think about other ways to use map. Look back at answer key to exam 3. Look at the reading on homogeneous lists.

What's the latest I can ask for an extension?

6 p.m. Monday.

Quiz

Project

The problem of sorting

Writing sorting algorithms

Examples: Insertion, selection, etc

Formalizing the problem