{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS 115 – SOS Review Package – Midterm

Ca make contact jp pretti jprettiuwaterlooca hello

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: l be the same as the contact that received the original email. The contact that receives the reply email will be the same as the contact that sent the original email. The subject of the reply email will be the same as the subject of the original email except that it will start with "RE: ". The message of the reply email will be the string consumed by the reply function, followed by a space, followed by the name of the sender, followed by a space, followed by the word "said" followed by a space followed by the original message. For example:(reply (make-email (make-contact "Sandy Graham" "[email protected]") (make-contact "J.P. Pretti" "[email protected]") "Hello" "I love CS115!") "Me too.") produces(makeemail (make-contact "J.P. Pretti" "[email protected]") (make-contact "Sandy Graham" "[email protected]") "RE: Hello" "Me too. Sandy Graham said I love CS115!") (define-struct contact (name email_address)) ;; A contact is a structure (make-contact n e) where ;; n is a non ­empty string representing a person's name and ;; e is a non ­empty string representing a person's email address (define-struct email (from to subject message)) ;; An email is a structure (make-email f t s m) where ;; f is a contact representing who sent the email, ;; t is a contact representing who received the email, ;; s is a string representing the subject of the email, and ;; m is a non ­empty string representing the text of the message (define (reply an_email new_message) (make-email (email-to an_email) (email-from an_email) (string-append "RE: " (email-subject an_email)) (string-append new_message " " (contact-name(email-from an_email)) " said " (email-message an_email)))) ;Tests: (check-expect (reply (make-email (make-contact "Sandy Graham" "[email protected]") (make-contact "J.P. Pretti" "[email protected]") "Hello" "I love CS115!") "Me too.")(make-email(make-contact "J.P. Pretti" "[email protected]")(make-contact "Sandy Graham" "[email protected]") "RE: Hello" "Me too. Sandy Graham said I love CS115!")) LISTS Formal Data Definition: A list is either: • Empty or • (cons f r) where o f is a value and o r is a list When we talk about a list, we think of a list with two parts: 1. the FIRST element of the list 2. the REST of the list (which is a list as well) Ex. (define list1 (cons ‘a (cons ‘b (cons ‘c (cons ‘d empty))))) (define list2 empty) Using the definition of the list above: (first list1) -> ‘a (rest list1) -> (cons ‘b (cons ‘c (cons ‘d empty))) (first (rest alist) -> ‘b...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern