CPS 343/543 Lecture notes: Tail calls and
continuation-passing style
Coverage: [EOPL] Chapter 7 (pp. 241-243), §8.1
(pp. 301-308), [TSPL] §§3.2 (pp. 62-70)
and 3.4 (pp. 75-77),
and [TSS] Chapter 19 (pp. 154-177)
Recursive control behavior
Tail recursion
Continuation-passing style
Full circle
| call-by-name | (delay ...) | (force ...) |
| continuations | (call/cc ...) | (k ...) |
| parallelism | suspend | resume |
problems side-effects cause for call-by-name akin to synchronization
problem for shared memory [PLPP] p. 512
Applications
of continuations
- non-local (abnormal) exits (for exceptional handling)
for efficiency
(i.e., to prevent returning through several layers of recursion)
- backtracking
- breakpoints (as used in debuggers)
- thunks (call-by-name parameters)
- multi-threading and multi-tasking (e.g., co-routines)
- iterators (see [TSS] Chapter 19)
- human-computer dialogs
End of Scheme
- take away: exotic programming languages are powerful (we have
only seen the tip of the iceberg in this class) and poorly understood
- they are an ideal lens through which to study the core concepts
of programming languages (and computer science in general),
- and they can be your claim to fame and fortune, there are too
many success stories to mention (e.g., Viaweb (Paul Graham and Robert
Morris), Orbitz, emacs, and AutoCAD are just some)
References
| [EOPL] |
D.P. Friedman, M. Wand, and C.T. Haynes.
Essentials of Programming Languages.
MIT Press, Second edition, 2001. |
| [PLPP] |
K.C. Louden.
Programming Languages: Principles and Practice.
Brooks/Cole, Pacific Grove, CA, Second edition, 2002.
|
| [TSS] |
D.P. Friedman and M. Felleisen.
The Seasoned Schemer.
MIT Press, Cambridge, MA, 1996.
|
| [MS] |
J.S. Miller.
Multischeme: A Parallel Processing System Based on MIT Scheme.
Ph.D. dissertation, Massachusetts Institute of Technology, 1987.
|
|