6.6

Homework 8

home work!

Programming Language ISL+

Due Date Friday, November 1 at 6pm

Purpose To practice the use of lambda and local as well as work on the project.

Expectations
  • You should submit a single .rkt file containing your responses to all exercises via the Handin Server. We accept NO email submissions. Failure to submit a .rkt file will result in a 0.

  • You are only allowed to use the language specified at the top of this page: failure to do so will result in a 0.

  • Your code MUST conform to the guidelines outlined in the style guide on the course website. The style guide will be updated as the semester progresses so please remember to read it before submitting each assignment.

  • You must follow all the steps of the design recipe when completing this assignment.

  • Please be sure to look at the feedback for assignment 6 before submitting, as we will be grading you more harshly on things we have warned you about before.

  • You must submit this assignment with your partner.

Exercise 1 Design the function make-line that given a slope and an y-intercept (two numbers) produces a function which, given an x-coordinate, will produce the y-coordinate on the line defined by that slope and y-intercept. Recall that y=mx + b, where m is the slope and b is the y-intercept. You must produce two versions of the code for this function, one using local and the other lambda (you do not need to reproduce the signature/purpose/tests).

The remainder of the problems in this assignment relate to the project. First, look back to the description in Homework 5 to remind you and revise your data definitions as necessary per your graded feedback.

In this assignment you will design functions that will be useful for the project. Later, you will design a few more functions as well as the World Program that pulls them all together.

For problems involving lists, you will be evaluated upon appropriate application of list abstractions, as well as local/lambda/helper functions. When developing signatures, be sure to provide as general a signature as is appropriate.

And as always, be sure to always apply the Design Recipe!

Exercise 2 Design the function return-former that takes two arguments and always returns the value of the first argument.

Exercise 3 Design a pair of functions: next-index and prev-index. Each is supplied a list and an index into that list. The next-index function should return the next valid index (or 0 if the supplied index is the last valid index). The prev-index should return the valid index before that which was supplied (or the highest valid index, if 0 was supplied).

Exercise 4 In Homework 5, Exercise 4, you designed a flatten function. For this exercise, you are to improve upon your design: first, abstract the signature such that it flattens a list of lists into a single list; and second, implement the function using a list abstraction instead of the list template.

Exercise 5 Design the function training-fnames that produces a list of file paths (each of which is a String). The file paths should follow a very particular pattern: "train/d_i_j.txt" where j is {0, 1, ... 9} and and i is {1, 2, ... n} (where n is a supplied number of examples per digit). An example test has been supplied to help you understand the problem.
(check-expect
 (training-fnames 3)
 (list "train/d_1_0.txt" "train/d_2_0.txt" "train/d_3_0.txt"
       "train/d_1_1.txt" "train/d_2_1.txt" "train/d_3_1.txt"
       "train/d_1_2.txt" "train/d_2_2.txt" "train/d_3_2.txt"
       "train/d_1_3.txt" "train/d_2_3.txt" "train/d_3_3.txt"
       "train/d_1_4.txt" "train/d_2_4.txt" "train/d_3_4.txt"
       "train/d_1_5.txt" "train/d_2_5.txt" "train/d_3_5.txt"
       "train/d_1_6.txt" "train/d_2_6.txt" "train/d_3_6.txt"
       "train/d_1_7.txt" "train/d_2_7.txt" "train/d_3_7.txt"
       "train/d_1_8.txt" "train/d_2_8.txt" "train/d_3_8.txt"
       "train/d_1_9.txt" "train/d_2_9.txt" "train/d_3_9.txt"))

Exercise 6 Design the function fname->label that, when supplied with a file name that ends in #.??? (such as those in Exercise 5) returns the # as an integer. For example, (fname->label "hello2.jpg") should return the number 2.

Exercise 7 Design the function map-lol, which maps a list of lists of one type to another using a function. For example...
(check-expect (map-lol
               string->number
               (list
                (list "0" "0" "0")
                (list "1" "2" "3")
                (list "3" "2" "1")))
              (list
               (list 0 0 0)
               (list 1 2 3)
               (list 3 2 1)))

Exercise 8 Design the function f-left-to-right that calls a function using a supplied non empty list in left-to-right order. For example, (f-left-to-right - (list 1 2 3)) should be evaluated as (- (- 1 2) 3) = -4.

Exercise 9 Recall the data definitions from Homework 5:
; A Feature is an integer in [0, 255]
; and represents a grayscale pixel
 
; A Bitmap is a [List-of [List-of Feature]]
; and represents a grid of grayscale pixels
Design the function bitmap->image that produces a visualization of a grid of features. Each visualized feature should be a square, a value of 255 is black, 0 is white, and values in between are various shades of gray. For example, the following code should produce the image bitmap image.
(bitmap->image (list
                (list 200 255 205)
                (list 255 0   213)
                (list 252 255 105)))
To produce a greyscale color, use make-color with the same number 3 times. For example, pure white is (make-color 255 255 255) and pure black is (make-color 0 0 0).

Exercise 10 Design the function smallest-of-list-by-f that finds the first element in a non-empty list that minimizes a supplied function. Note that this is commonly known as argmin and you are not allowed to use the argmin function in this exercise, which is already defined in ISL. An example has been provided below:
(check-expect
 (smallest-of-list-by-f length
                        (list
                         (list 1 2 3)
                         (list 100)
                         (list -1000 -99 -1 0)
                         (list 2)))
 (list 100))