CS115 Lecture Notes - Lecture 5: Recursive Definition

68 views2 pages
elliehaj0807 and 36989 others unlocked
CS115 Full Course Notes
13
CS115 Full Course Notes
Verified Note
13 documents

Document Summary

Recursive definition: one or more base cases and one or more recursive cases. Empty constant: empty, (cons f r) where f is a value and r is a list, empty = (, ;; a (listof sym) is one of: ;; my-listof-x-fun: (listof x) -> any (define (my-listof-x-fun lst) (cond. Consumes an element of any type and a list, returns true if. Built-in list functions and only if element appears in list. Producing lists from lists: negate-list consumes a list and produces same list with each number negated empty)) (negate-list empty) -> empty (negate-list (cons 2 (cons -12 empty))) -> (cons -2 (cons 12 (define (negate-list alon) (cond. [else (cons ( (first alon)) (negate-list (rest alon)))]): removing elements from a list (define (remove-all n alon) (cond. [else . (first alon) . (remove-all n (rest alon))])) ^produces list with all occurrences of n removed from alon (define (singles alon) (cond. [else . (first alon) . (singles (rest alon))]))

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