CS115 Lecture 7: Week 7 / Module 7: Processing two lists or numbers
elliehaj0807 and 36989 others unlocked
13
CS115 Full Course Notes
Verified Note
13 documents
Document Summary
Understand the three approaches to designing functions that consume two lists (or a list and a number, or two numbers) and know which one is suitable to use in a given situation. Case 1: a list going along for the ride". [else ( rst alist) (my-list-fun (rest alist)) ])) (cond [(empty? alist) ] ;; (de ne (my-alongforride-fun list1 list2) (cond [(empty? list1) ] [else ( rst list1) (my-alongforride-fun (rest list1) list2) ])) Example: my-append consumes two lists (list1/list2) and produces the list with empty in list1 replaced by list2. ;; (my-append list1 list2) produces a new list with list2 appended to list1. ;; my-append: (listof any) (listof any) -> (listof any) ;; example: (check-expect (my-append (cons 1 empty) (cons 2 empty)) (cons 1 (cons 2 empty))) (de ne (my-append list1 list2) (cond [(empty? list1) list2] [else (cons ( rst list1) (my-append (rest list1) list2))]))