Chapter 13 - Teach Yourself Scheme in Fixnum Days[Go to...

Info icon 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 13 Jumps One of the signal features of Scheme is its support for jumps or nonlocal control . Specifically, Scheme allows program control to jump to arbitrary locations 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-continuation The operator call-with-current-continuation call s its argument, which must be a unary procedure, with a 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 . 6 The 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 1 to whatever is used to fill its hole. This is what the argument of call/cc is called with . Remember that the argument of call/cc is the procedure (lambda (k) (1 of 8) [2/6/2008 11:41:30 AM]
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.