CS115 Lecture Notes - Lecture 5: Recursive Definition
elliehaj0807 and 36989 others unlocked
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))]))