;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "2017-fall-reader.rkt" "csc104")((modname Week-8-Lab) (compthink-settings #hash((prefix-types? . #f)))) ; Exercises for Week 8 ; ==================== ; The quiz on November 1st th will be related to this exercise. ; You should do very well on the quiz if you try out everything below. ; Instructors/TAs are available before quizzes for questions, 10--3 on Wednesday in BA 3175. ; Quiz Rooms ; ---------- ; TUT0201 11-12 ; 11:30 surnames A--L RS310 ; 11:30 surnames M--V HA316 ; 11:45 surnames W--Z RS310 ; ; TUT0301 12--1 ; 12:30 surnames A--M BF323 ; 12:45 surnames N--Z BF323 ; ; TUT0401 1--2 ; 1:30 surnames A--M UC256 ; 1:45 surnames N--Z UC256 ; ; TUT0501 2--3 ; 2:30 surnames A--M RS310 ; 2:45 surnames N--Z RS310 ; ; TUT0101 3--4 ; 3:30 surnames A--M RW140 ; 3:45 surnames N--Z RW140 ; Here is a function definition: (define (berry? s) (equal? "berry" (substring s (- (string-length s) 5) (string-length s)))) ; Show the result value of: #;(substring "blueberry" 3 6) ; Show the steps for: #;(berry? "raspberry") #;(berry? "cherry") ; Try out the function string-contains?, by trying the following three expressions. ; (string-contains? s1 s2) determines whether s1 is a substring of s2. ; #;(string-contains? "ap" "grape") #;(string-contains? "ap" "raspberry") #;(string-contains? "ap" "apple") ; Here are two function definitions: (define (string-first s) (substring s 0 1)) (define (string-rest s) (substring s 1 (string-length s))) ; Show the steps for: #;(string-first "cherry") #;(string-rest "cherry") ; Here is a function definition: (define (dv s) (cond [(equal? s "") ""] [(string-contains? (substring s 0 1) "aeiou") (dv (string-rest s))] [else (string-append (string-first s) (dv (string-rest s)))])) ; Show the steps for the following expressions. ; In each case, you may omit showing the steps you already showed for an earlier expression. ; You may also omit showing the steps for string-first and string-rest. ; You may also omit as many of the cond expressions as you like. #;(dv "") #;(dv "t") #;(dv "at") #;(dv "cat") ; In other words, show these steps, omitting as many of the (cond ...) steps as you like: #;(step parallel (hide string-first string-rest) (dv "")) #;(step parallel (hide string-first string-rest (dv "")) (dv "t")) #;(steps parallel (hide string-first string-rest (dv "") (dv "t")) (dv "at")) #;(step parallel (hide string-first string-rest (dv "") (dv "t") (dv "at")) (dv "cat")) ; Here is a function definition: (define (include e a-list) (append (list e) a-list)) ; Show the steps for: #;(include "tuna" (list "fish" "sandwich")) ; Here is a function definition: (define (p LoL single doubled) (cond [(empty? LoL) (include single doubled)] [(empty? single) (p (rest LoL) (list (first LoL)) doubled)] [else (p (rest LoL) (list) (include (include (first LoL) single) doubled))])) ; Show the steps for the following expressions. ; In each case, you may omit showing the steps you already showed for an earlier expression. ; You may also omit showing the steps for include. ; You may also omit as many of the cond expressions as you like. #;(p (list) (list 3) (list (list 2 1))) #;(p (list 3) (list) (list (list 2 1))) #;(p (list 2 3) (list 1) (list)) #;(p (list 1 2 3) (list) (list)) ; In other words, show these steps, omitting as many of the (cond ...) steps as you like: #;(step parallel (hide include) (p (list) (list 3) (list (list 2 1)))) #;(step parallel (hide include (p (list) (list 3) (list (list 2 1)))) (p (list 3) (list) (list (list 2 1)))) #;(step parallel (hide include (p (list 3) (list) (list (list 2 1)))) (p (list 2 3) (list 1) (list))) #;(step parallel (hide include (p (list 2 3) (list 1) (list))) (p (list 1 2 3) (list) (list)))