This preview shows pages 1–3. Sign up to view the full content.
Teach Yourself Scheme in Fixnum Days [Go to first, previous, next page; contents; index]Chapter 13JumpsOne of the signal features of Scheme is its support for jumps or nonlocal control. Specifically, Scheme allows program control to jump to arbitrarylocations in the program, in contrast to the more restrained forms of program control flow allowed by conditionals and procedure calls. Scheme's nonlocal control operator is a procedure named call-with-current-continuation. We will see how this operator can be used to create a breathtaking variety of control idioms.13.1 call-with-current-continuationThe operator call-with-current-continuationcalls its argument, which must be a unary procedure, witha value called the ``current continuation''. If nothing else, this explains the name of the operator. But it is a long name, and is often abbreviated call/cc.6The current continuation at any point in the execution of a program is an abstraction of the rest of the program. Thus in the program(+ 1 (call/cc(lambda (k)(+ 2 (k 3)))))the rest of the program, from the point of view of the call/cc-application, is the following program-with-a-hole (with representing the hole):(+ 1 )In other words, this continuation is a program that will add 1to whatever is used to fill its hole.This is what the argument of call/ccis called with. Remember that the argument of call/ccis the procedure(lambda (k) (1 of 8) [2/6/2008 11:41:30 AM]
has intentionally blurred sections.
Sign up to view the full version.