CS115 Lecture 7: Week 7 / Module 7: Processing two lists or numbers

59 views4 pages
elliehaj0807 and 36989 others unlocked
CS115 Full Course Notes
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))]))

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents