joshua eckroth [email protected]. the plan 1.review some functions. 2.write more functions....
TRANSCRIPT
![Page 2: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/2.jpg)
![Page 3: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/3.jpg)
![Page 4: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/4.jpg)
The Plan
1. Review some functions.2. Write more functions.3. Consider the nature of recursion.4. Look at the call stack.5. Discover tail-call optimization.
![Page 5: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/5.jpg)
L =
(first L)
(rest L)
![Page 6: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/6.jpg)
L =
(cons 'a L)
'a
![Page 7: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/7.jpg)
Review: Length of L
(define (length L) (cond [(null? L) 0] [else (+ 1 (length (rest L)))]))
![Page 8: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/8.jpg)
Review: Is e a member of L?
(define (member e L) (cond [(null? L) #f] [(equal? e (first L)) #t] [else (member e (rest L))]))
![Page 9: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/9.jpg)
Review: Remove first e from L
(define (remove e L) (cond [(null? L) '()] [(equal? e (first L)) (rest L)] [else (cons (first L) (remove e (rest L)))]))
![Page 10: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/10.jpg)
Task: Reverse L
(define (reverse L) (cond [__________ __________] [________ _______________________]))
![Page 11: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/11.jpg)
Task: Reverse L
(define (reverse L) (cond [(null? L) '()] [else (append (reverse (rest L)) (list (first L)))]))
![Page 12: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/12.jpg)
Task: Write the “range”function
(define (range lo hi) (cond [_________ ___________] [______ ___________________________]))
![Page 13: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/13.jpg)
Task: Write the “range”function
(define (range lo hi) (cond [(> lo hi) '()] ;; or >= [else (cons lo (range (+ 1 lo) hi))]))
![Page 14: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/14.jpg)
Recursion in “nature.”
![Page 15: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/15.jpg)
A list is the empty list (null),OR,
a “first” value,followed by a list (“rest”).
![Page 16: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/16.jpg)
0 = {} n + 1 = n U {n}
1 = {0} = {{}}2 = {0, 1} = {{}, {{}}}3 = {0, 1, 2} = {{}, {{}}, {{}, {{}}}}
The Natural Numbers
![Page 17: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/17.jpg)
'')'( bgafbgaf
'')'( fggffg
))(()( xghxf
)('))((')(' xgxghxf
Derivatives
Sum rule:Product rule:
Chain rule:If,Then,
![Page 18: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/18.jpg)
def foobar(x): if x < 10: for y in baz: while x > 0: if z == y: print “Too much nesting!”
(define (foobar x) (if (< x 10) (for ([y baz]) (do () (<= x 0) (if (= z y) (display “Too much nesting!”))))))
Languages
![Page 19: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/19.jpg)
I ate a banana.
I know that I wishI ate a banana.
I wish I ate a banana.
Susan’s brother’s wife’ssister’s cat’s favorite toy…
![Page 20: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/20.jpg)
… language makes infinite use
of finite means …
- Wilhelm von Humboldt
![Page 21: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/21.jpg)
“[T]he only reason language needs to be recursive is because its function is to express recursive thoughts. If there were not any recursive thoughts, the means of expression would not need recursion either.”
- Pinker & Jackendoff, “The faculty of language: What’s special about it?” Cognition, 2005, 95(2), pp. 201-236
![Page 22: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/22.jpg)
The thinker thinks of thinking of thinking.
Corballis, The Recursive Mind: The Origins of Human Language, Thought, and Civilization, Princeton University Press, 2011
![Page 23: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/23.jpg)
http://www.cs.yale.edu/quotes.html
More Perlisisms:
Recursion is the root of computation since it trades description for time.
- Alan Perlis
![Page 24: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/24.jpg)
.0 and 0 if
0 and 0 if
0 if
))1,(,1(
)1,1(
1
),(
nm
nm
m
nmAmA
mA
n
nmA
Ackermann function
Looks harmless!
![Page 25: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/25.jpg)
Ackermann function(define (ackermann m n) (cond [(= m 0) (+ 1 n)] [(= n 0) (ackermann (- m 1) 1)] [else (ackermann (- m 1) (ackermann m (- n 1)))]))
![Page 26: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/26.jpg)
A(2, 2) =
![Page 27: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/27.jpg)
A(2, 2) = 9
![Page 28: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/28.jpg)
A(2, 2) = 9
I count 27 function calls.
![Page 29: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/29.jpg)
A(3, 2) =
![Page 30: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/30.jpg)
A(3, 2) = 29
![Page 31: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/31.jpg)
A(3, 2) = 29
540 calls!
![Page 32: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/32.jpg)
A(4, 2) =
![Page 33: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/33.jpg)
A(4, 2) = 20035299304068464649790723515602557504478254755693454734
![Page 34: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/34.jpg)
![Page 35: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/35.jpg)
Why does recursionget a bad rap?
![Page 36: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/36.jpg)
Stack frames
![Page 37: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/37.jpg)
![Page 38: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/38.jpg)
![Page 39: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/39.jpg)
![Page 40: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/40.jpg)
![Page 41: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/41.jpg)
![Page 42: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/42.jpg)
![Page 43: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/43.jpg)
![Page 44: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/44.jpg)
![Page 45: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/45.jpg)
![Page 46: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/46.jpg)
![Page 47: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/47.jpg)
Task: “Flatten” L
(define (flatten L) (cond [_________ ____] [______________ (append ____________________ ____________________)] [______ ________________________________ ]))
![Page 48: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/48.jpg)
Task: “Flatten” L
(define (flatten L) (cond [(null? L) '()] [(list? (first L)) (append (flatten (first L)) (flatten (rest L)))] [else (cons (first L) (flatten (rest L)))]))
![Page 49: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/49.jpg)
Quiz: Fill in detailsfor flatten’s call stack.
![Page 50: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/50.jpg)
![Page 51: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/51.jpg)
![Page 52: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/52.jpg)
![Page 53: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/53.jpg)
![Page 54: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/54.jpg)
![Page 55: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/55.jpg)
![Page 56: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/56.jpg)
![Page 57: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/57.jpg)
![Page 58: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/58.jpg)
![Page 59: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/59.jpg)
![Page 60: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/60.jpg)
![Page 61: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/61.jpg)
![Page 62: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/62.jpg)
![Page 63: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/63.jpg)
![Page 64: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/64.jpg)
![Page 65: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/65.jpg)
![Page 66: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/66.jpg)
![Page 67: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/67.jpg)
![Page 68: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/68.jpg)
![Page 69: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/69.jpg)
![Page 70: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/70.jpg)
![Page 71: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/71.jpg)
![Page 72: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/72.jpg)
![Page 73: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/73.jpg)
Tail-recursion
Sometimes, recursion can beboth fast and expressive.
![Page 74: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/74.jpg)
Quiz: Identify tail-calls.(define (example L) (if (= 1 0) #f (example (rest L))))
(define (bloop a b c) (cond [(bloop 1 2 3) (bloop 3 2 1)] [else (rest (bloop 0 0 0))]))
![Page 75: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/75.jpg)
Quiz: Identify tail-calls.(define (example L) (if (= 1 0) #f (example (rest L))))
(define (bloop a b c) (cond [(bloop 1 2 3) (bloop 3 2 1)] [else (rest (bloop 0 0 0))]))
![Page 76: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/76.jpg)
Quiz: Identify tail-calls.(define (example L) (if (= 1 0) #f (example (rest L))))
(define (bloop a b c) (cond [(bloop 1 2 3) (bloop 3 2 1)] [else (rest (bloop 0 0 0))]))
![Page 77: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/77.jpg)
Review: Length of L
(define (length L) (cond [(null? L) 0] [else (+ 1 (length (rest L)))]))
![Page 78: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/78.jpg)
A tail-recursive length(define (lengthT L Acc) (cond [(null? L) ________] [else (lengthT (rest L) ____________)]))
![Page 79: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/79.jpg)
A tail-recursive length(define (lengthT L Acc) (cond [(null? L) Acc] [else (lengthT (rest L) (+ 1 Acc)]))
(define (length L) (length L 0))
![Page 80: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/80.jpg)
![Page 81: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/81.jpg)
![Page 82: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/82.jpg)
![Page 83: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/83.jpg)
![Page 84: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/84.jpg)
![Page 85: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/85.jpg)
![Page 86: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/86.jpg)
![Page 87: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/87.jpg)
![Page 88: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/88.jpg)
Review: Remove first e from L
(define (remove e L) (cond [(null? L) '()] [(equal? e (first L)) (rest L)] [else (cons (first L) (remove e (rest L)))]))
![Page 89: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/89.jpg)
A tail-recursive remove(define (removeT e L Acc) (cond [(null? L) _______] [(equal? (first L) e) __________________________] [else (remove e (rest L) ______________________]))
(define (remove e L) (remove e L '()))
![Page 90: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/90.jpg)
A tail-recursive remove(define (removeT e L Acc) (cond [(null? L) Acc] [(equal? (first L) e) (append Acc (rest L))] [else (remove e (rest L) (cons (first L) Acc))]))
(define (remove e L) (remove e L '()))
![Page 91: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/91.jpg)
Quiz: Write reverse andrange with tail-recursion.
![Page 92: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/92.jpg)
Tail-call optimizationkeeps a small stack.
![Page 93: Joshua Eckroth joshuaeckroth@gmail.com. The Plan 1.Review some functions. 2.Write more functions. 3.Consider the nature of recursion. 4.Look at the](https://reader036.vdocuments.mx/reader036/viewer/2022062511/5516c416550346f0208b59f2/html5/thumbnails/93.jpg)
Recursion is the root of computation since it trades description for time, butnot necessarily.