6.6

Assignment 7

home work!

Programming Language ISL

Due Date Tuesday 6/4 at 10:00pm

Purpose To practice using abstractions.

Finger Exercises

Exercise 2 HtDP Exercise 237

Exercise 3 HtDP Exercise 238

Exercise 4 HtDP Exercise 240

Exercise 5 HtDP Exercise 241

Graded Exercises

You must use list abstractions (map, filter, ormap, andmap or foldr) for the following exercises unless directed otherwise.

Exercise 6 Design a function that will determine if every string in a list is alphabetic.

Exercise 7 Use foldr and build-list to design a function that computes the factorial of a natural number. You may need to look up build-list in the helpdesk.

Exercise 8 Interpret the following data definition:

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

Using a list abstraction, design "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.

Exercise 9 Consider the following data definitions:

(define-struct tweet [author text])
(define-struct image-tweet [author text image])
(define-struct retweet [author tweet])
; A Tweet is one of:
; - (make-tweet String String)
; - (make-image-tweet String String Image)
; - (make-retweet String Tweet)
; INTERPRETATION:  A tweet is either a message (make-tweet),
; a message and an image (make-image-tweet), or a retweet
; of another tweet (make-retweet).  All tweets have authors.
 
; A Feed is a [List-of Tweet]
; INTERPREATION:  A list of the Tweets in a user's feed.

Without using the list abstractions (like map, filter, etc.), design the function count-tweets.v1, which accepts a Feed and returns a Number representing the total number of Tweets in the Feed. Note that a retweet has more than one Tweet in it. For example

(check-expect
  (count-tweets.v1
   (list (make-tweet "foo" "bar")
         (make-retweet "baz"
                       (make-retweet "blah"
                                     (make-image-tweet "arg"
                                                       "grr"
                                                       empty-image)))))
  4)

Exercise 10 Redesign the function count-tweets using any appropriate list abstractions (map, filter, etc.) Call this function count-tweets.v2. You may use any helper functions that you designed for the previous exercise when completing this one — except, of course, for count-tweets.v1 itself!

For the next two exercises, you can assume the functions will only be called with non-empty lists:
; An [NEList-of X] is one of:
; - (cons X '())
; - (cons X [NEList-of X])

Exercise 11 Design a function that will output the absolute value of every number in a list of numbers.

Exercise 12 Design a function that will return the largest number in a non-empty list of numbers.