100% found this document useful (3 votes)
720 views225 pages

The Seasoned Schemer

The goal of this book is to teach the reader to think recursively

Uploaded by

VickyDX
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
100% found this document useful (3 votes)
720 views225 pages

The Seasoned Schemer

The goal of this book is to teach the reader to think recursively

Uploaded by

VickyDX
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 225
The Seasoned Schemer A (eee. i ig ie ae ud ~ Daniel P. Friedman and Matthias Felleisen Foreword and Afterword by Guy L. Steele Jr. The First Ten Commandments The First Commandment When recurring on a list of atoms, lat, ask two questions about it: (null? lat) and else. When recurring on a number, n, ask two questions about it: (zero? n) and else. When recurring on a list of S-expressions, 1, ask three question about it: (null? 1), (atom? (car 1)), and else. The Second Commandment Use cons to build lists. The Third Commandment When building a list, describe the first typi- cal element, and then cons it onto the natu- ral recursion. The Fourth Commandment Always change at least one argument while recurring. When recurring on a list of atoms, lat, use (cdr lat). When recurring on a num- ber, n, use (subi n). And when recurring on a list of S-expressions, !, use (car 1) and (cdr 1) if neither (null? 1) nor (atom? (car 1) are true. It must be changed to be closer to termina- tion. The changing argument must be tested in the termination condition: when using cdr, test termination with null? and when using subf, test termination with zero? The Fifth Commandment When building a value with & ,always use 0 for the value of the terminating line, for adding 0 does not change the value of an addition. When building a value with x, always use 1 for the value of the terminating line, for multiplying by 1 does not change the value of a multiplication. When building a value with cons, always consider () for the value of the terminating line. The Sixth Commandment Simplify only after the function is correct. ‘The Seventh Commandment Recur on the subparts that are of the same nature: © On the sublists of a list. © On the subexpressions of an arithmetic expression. The Eighth Commandment Use help functions to abstract from represen- tations. The Ninth Commandment Abstract common patterns with a new func- tion. The Tenth Commandment Build functions to collect more than one value at a time. The Next Ten Commandments The The The The The Eleventh Commandment Use additional arguments when a function needs to know what other arguments to the function have been like so far. ‘Twelfth Commandment Use (letree ...) to remove arguments that do not change for recursive applications. Thirteenth Commandment Use (letree functions. ++.) to hide and to protect Fourteenth Commandment Use (letec ...) to return values abruptly and promptly. Fifteenth Commandment Use (let ...) to name the values of repeated expressions in a function definition if they may be evaluated twice for one and the same use of the function. And use (let ...) to name the values of expressions (without set!) that are re-evaluated every time a function is used. The The The The The Sixteenth Commandment Use (set! ...) only with names defined in (let ...)s. Seventeenth Commandment Use (set! 2...) for (let ((z ...)) ...) only if there is at least one (lambda ... between it and the (let ...), or if the new value for z is a function that refers to z. Eighteenth Commandment Use (set! x...) only when the value that 2 refers to is no longer needed. Nineteenth Commandment Use (set! ...) to remember valuable things between two distinct uses of a function. Twentieth Commandment When thinking about a value created with (letce ...), write down the function that is equivalent but does not forget. Then, when you use it, remember to forget.

You might also like