CS 115 – SOS Review Package – Midterm

Ca make contact jp pretti jprettiuwaterlooca hello

Info iconThis 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" "slgraham@uwaterloo.ca") (make-contact "J.P. Pretti" "jpretti@uwaterloo.ca") "Hello" "I love CS115!") "Me too.") produces(makeemail (make-contact "J.P. Pretti" "jpretti@uwaterloo.ca") (make-contact "Sandy Graham" "slgraham@uwaterloo.ca") "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" "slgraham@uwaterloo.ca") (make-contact "J.P. Pretti" "jpretti@uwaterloo.ca") "Hello" "I love CS115!") "Me too.")(make-email(make-contact "J.P. Pretti" "jpretti@uwaterloo.ca")(make-contact "Sandy Graham" "slgraham@uwaterloo.ca") "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

Ask a homework question - tutors are online