6.6

Homework 7

home work!

Programming Language ISL

Due Date Friday, October 25 at 6pm

Purpose To practice the use of pre-defined list abstractions.

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 5 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 new partner (assigned in lab on Tuesday, October 22nd). Please make sure you can submit with your partner as soon as possible to ensure you do not miss the deadline.

For the following exercises, refer to the data definition below, and use pre-defined list abstraction(s) when appropriate.

(define-struct book [title authors page-count])
(define-struct article [title authors url word-count])
 
; An InfoSource is one of:
; - (make-book String [List-of String] Number)
; - (make-article String [List-of String] String Number)
; and represents either:
; - a book's name, author(s), and number of pages
; - an online article's name, author(s), url, and number of words
 
(define IS-BOOK-1
  (make-book
   "Algorithms to Live By: The Computer Science of Human Decisions"
   (list "Brian Christian" "Tom Griffiths")
   368))
 
(define IS-BOOK-2
  (make-book
   (string-append
    "Hidden Figures: "
    "The American Dream and the Untold Story of the Black Women Who Helped Win the Space Race")
   (list "Margot Lee Shetterly")
   384))
 
(define IS-ARTICLE-1
  (make-article
   "Teach Yourself Programming in Ten Years"
   (list "Peter Norvig")
   "http://norvig.com/21-days.html"
   1790))
 
(define IS-ARTICLE-2
  (make-article
   "Is There a Fix for Impostor Syndrome?"
   (list "Elizabeth Churchill")
  "https://interactions.acm.org/archive/view/may-june-2018/is-there-a-fix-for-impostor-syndrome"
   1655))
 
; infosource-temp : InfoSource -> ?
(define (infosource-temp i)
  (...
   (cond [(book? i) (... (book-title i)
                         (los-temp (book-authors i))
                         (book-page-count i) ...)]
         [(article? i) (... (article-title i)
                            (los-temp (article-authors i))
                            (article-url i)
                            (article-word-count i) ...)])))

Exercise 1 Design the function only-articles that accepts a list of information sources, and produces a list of only the online articles.

Exercise 2 Design the function all-authors that returns a single list of the all the authors in a list of info sources. You do not need to remove duplicates, if any exist.

Exercise 3 Design the function num-books that counts the number of books in a list of info sources.

Exercise 4 Design the function multi-author? that determines if a supplied info source list contains at least one source with more than one author.

Exercise 5 Design the function total-words that computes the total number of words in a list of info sources. Assume that a book page has 250 words.

Exercise 6 Design the function secure-articles? that returns true if all articles in a list of info sources are served from secure URLs (i.e., start with "https").

Exercise 7 Design the function natnum->books that returns a list of books according to the following pattern...
(list (make-book "0" (list "0") 1)
      (make-book "1" (list "0" "1") 2)
      (make-book "2" (list "0" "1" "2") 3) ...)
The number input to the function should determine the length of the output list.

Exercise 8 Design the function byline that produces a comma-separated String of the authors of an info source, such as "By: Brian Christian, Tom Griffiths" or "By: Elizabeth Churchill". For sources with multiple authors, alphabetize the list (by the name as shown in the author list). Your function should not add an extra comma at the end of the list.