Problem Set 5h

This is the honors version of Problem Set 5; if you’re looking for the normal version, click here!

image

home work!

Programming Language ISL

Purpose This problem set concerns the design of abstractions.

Finger Exercises HtDP/2e: 205, 206, 209, 210

image

Problem 1 Exercise 210 from HtDP/2e

Problem 2 Exercise 212 from HtDP/2e

Problem 3 Exercise 213 from HtDP/2e

Problem 4 Exercise 214 and 215 from HtDP/2e

Problem 5 Interpret the following data definition:

; [List-of [Number -> Number]]

Design 0 at-0. The function consumes a list of functions from numbers to numbers and produces the list of results of applying these functions to 0.

Problem 6 Design find-string. The function consumes a [List-of String] and a String; it returns a true if and only if the given string is a member of the list.

Abstract find-string to generic-find-string so that the string comparison operation it uses is a parameter. Then use this abstraction to define find-string-case-sensitive, which should operate the same way as the original find-string, and find-string-case-insensitive, which has the same contract as find-string but ignores the case of alphabetic characters when comparing strings. That is, "a" is considered the same as "A" and so on; non-alphabetic characters must still match exactly. Look in the documentation for ISL to find appropriate primitive functions.

image

Problem 7 The local meteorological society keeps a list of records about the weather each day. They track the following attributes: zip code, humidity (as a percentage), and high and low temperatures (in Fahrenheit) for the day.

Here is the data definition for a weather record:
(define-struct weather (zip humidity high low))
; A Weather is a structure:
;    (make-weather String Number Number Number)
; interpretation: (make-weather z hum hi lo) is a day's weather
;   record where:
;  z is the 5-digit zip code where the data was collected
;  hum is the humidity as a percentage
;  hi and lo represent the day's high and low temperatures in
;    degrees Fahrenheit, and hi is greater than or equal to lo

Design a function muggy that, given a list of weather records, a humidity humid-threshold (expressed as a percentage), and a temperature temp-threshold (expressed in degrees Fahrenheit), eliminates from the list any weather records with a humidity lower than humid-threshold or a high temperature lower than temp-threshold.

Problem 8 Design a function near-origin that, given a list of Posns and a distance dist, eliminates all the posns in the list that are distance dist or more away from the origin (0,0).

Problem 9 Note the similarities and differences between muggy and near-origin. Design a function that abstracts over the differences and then use it to implement muggy.v2 and near-origin.v2. Be sure to test that the latter two behave the same as muggy and near-origin, respectively.