6.6

Assignment 11

home work!

Programming Language ISL

Due Date Thursday 10/25 at 9pm

Purpose To use pre-defined abstractions in interesting ways.

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

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

  • You are expected to use pre-defined abstractions when stated and/or when appropriate.

Exercise 1 Design a function which, given a list of numbers, uses map and filter to return the squares of the even numbers in the list. Do not compute squares you will not use in the end result.

Exercise 2 Design a second version of the same function which uses foldr so that you only iterate over the elements of the list once instead of twice.

Patterns like map-filter are useful shorthands for computations you often find yourself doing repeatedly!

Exercise 3 Design a function map-filter with foldr which will filter a list by some predicate and then apply a function to all of the remaining elements. Then, design the initial function a third time with this new abstraction. Explicitly test both functions.

Exercise 4 Revisit the Playlist problems from assignment Assignment 8. Design a function which given a list of playlists and a string, title, produces a new playlist with the given title which contains all of the videos of the given playlists (in the order given).

Be sure to use proper helpers so as to only make a playlist once. Do not walk a list more than once if not necessary.

You do not need to provide the templates for playlists and its associated data, but be sure to provide the definitions, and it couldn’t hurt to have examples to test on. :)

Exercise 5 Design a function scalar-matrix which given a natural number n and a number k, outputs an nxn matrix (list of list of numbers) where the diagonal (first element of the first row, second element of the second row... nth element of the nth row) entries are k and the other elements are 0.

Exercise 6 Design a function into, which takes in a list of list of natural numbers, lolon, and a natural number, n. n will operate as an index into the first entry in lolon, and the element at that location will operate as an index into the second entry in lolon, etc. until all of lolon is exhausted. Of course, lolon could be empty, in which case the function should produce n.

For example, (into (list (list 3 5) (list 100 101 102 103 104 2) (list 1 1 0) (list 50 60)) 1) should produce 50. list-ref will likely be helpful. Be sure to write a test on inputs which follow the signature but on which the function will produce an error (list-ref will throw an error on its own if the index is too big for the list).

Remember that lists are indexed starting at 0, which means the first element of a list has index 0.