This outline is also available in PDF.
Held: Wednesday, 13 September 2006
Summary: Today we continue our consideration of the process of recursion.
cond, follow the evaluation rules for that operation.
(define double (lambda (x) (+ x x))) (define a 5)
(double (double (* 7 (+ 1 a))))
(double (* 7 (+ 1 a)))
(* 7 (+ 1 a)).
(+ 1 a).
7is a primitive value, so we're done with it.
(+ 1 a)is a procedure application, so we evaluate its parameters.
1is a primitive value, so we're done with it.
ais the name for
5, so we use that.
(+ 1 5). Since
+is a built-in operation, we do what it's supposed to do, and the value of this sub-expression is
(* 7 6). Again, we rely on the built-in operation, and get
42for this subexpression.
(double 42). This time, we have a user-defined operation, so we plug in
xin the body, and get
(+ 42 42).
(double 84). This is left as an exercise for the reader.
sum, let us consider a variant in which we compute a similar value, but using subtraction rather than addition.
(define difference (lambda (numbers) (if (null? numbers) 0 (- (car numbers) (difference (cdr numbers)))))) (define new-difference (lambda (numbers) (new-difference-helper (car numbers) (cdr numbers)))) (define new-difference-helper (lambda (difference-so-far remaining) (if (null? remaining) difference-so-far (new-difference-helper (- difference-so-far (car remaining)) (cdr remaining)))))
I usually create these pages
on the fly, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Thu Nov 30 21:43:23 2006.
The source to the document was last modified on Mon Sep 4 08:43:33 2006.
This document may be found at
You may wish to validate this document's HTML ; ;Samuel A. Rebelsky, email@example.com
http://creativecommons.org/licenses/by-nc/2.5/or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.