Functional Problem Solving (CSC 151 2015F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric] [Remote Access]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Curtsinger (2015F)] [Davis (2013F)] [Rebelsky (2015S)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Overview
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.