6.6

Assignment 10

home work!

Programming Language ISL

Due Date Monday 10/22 at 9pm

Purpose To design and use abstractions.

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 the language specified at the top of this page: failure to do so will result in a 0.

  • You must submit with your new homework partner (received in lab on Tuesday, October 16th). Please ensure that you and your partner can submit by 5pm on Monday or we cannot guarantee that we will be able to resolve the issue before the deadline.

  • All steps of the design recipe are required unless otherwise specified. However, at this point we expect you are familar with the [List-of X] data definition and do not require it or its template.

  • [List-of X] notation should be used, such as [List-of Number], instead of LoN.

  • As you have only recently seen it in lecture, we do not yet expect you to use local; if you feel confident enough to use it you may, but no extra credit will be given for it.

(define-struct book [title author page-count])
(define-struct article [title author url word-count])
; An InfoSource is one of:
; - (make-book String String Number)
; - (make-article String String String Number)
; and represents either:
; - a book's name, author, and number of pages
; - an online article's name, author, url, and number of words
 
(define INFO-SOURCE/BOOK (make-book "On Directing Film" "David Mamet" 128))
(define INFO-SOURCE/ARTICLE
  (make-article "How Did Moonlight Win Best Picture?"
                "Kyle Buchanan"
                "http://www.vulture.com/2017/02/oscars-2017-how-did-moonlight-win-best-picture.html"
                1285))
 
; infosource-temp : InfoSource -> ?
(define (infosource-temp i)
  (cond [(book? i) (... (book-title i) (book-author i) (book-page-count i))]
        [(article? i) (... (article-title i)
                           (article-author i)
                           (article-url i)
                           (article-word-count i))]))

Exercise 1 Design a function (using the appropriate pre-defined list abstraction) that accepts a list of info sources, and produces a list of only the books.

Exercise 2 Design a function (using the appropriate pre-defined list abstraction) that returns a list of the titles of every info source in a list of info sources.

Exercise 3 Design a function which returns a String of all of the authors in a list of info sources, separated by " ". It is fine if your function produces a single trailing space at the end. You are not required to use a list abstraction for this function.

Exercise 4 Design a function which returns the total page count of the pages in a list of info sources. For articles, presume there are 100 words to a page and use ceiling to round up. You are not required to use a list abstraction for this function.

Exercise 5 Create an abstracted version of the above two functions (from Exercises 3 and 4). Comment out your old version with #; and re-define them with your new abstraction. The tests for your old functions should still pass, and so you do not have to directly write tests for this function.