Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Call-with-current-continuation
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Control flow operator in functional programming}} {{lowercase title}} In the [[Scheme (programming language)|Scheme]] [[computer programming]] language, the [[procedure (computer science)|procedure]] '''call-with-current-continuation''', abbreviated '''call/cc''', is used as a [[control flow]] operator. It has been adopted by several other programming languages. Taking a function <code>f</code> as its only argument, <code>(call/cc f)</code> within an expression is applied to the current [[continuation]] of the expression. For example <code>((call/cc f) e2)</code> is equivalent to applying <code>f</code> to the current continuation of the expression. The current continuation is given by replacing <code>(call/cc f)</code> by a variable <code>c</code> bound by a lambda abstraction, so the current continuation is <code>(lambda (c) (c e2))</code>. Applying the function <code>f</code> to it gives the final result <code>(f (lambda (c) (c e2)))</code>. As a complementary example, in an expression <code>(e1 (call/cc f))</code>, the continuation for the sub-expression <code>(call/cc f)</code> is <code>(lambda (c) (e1 c))</code>, so the whole expression is equivalent to <code>(f (lambda (c) (e1 c)))</code>. In other words it takes a "snapshot" of the current control context or control state of the program as an object and applies <code>f</code> to it. The continuation object is a [[first-class value]] and is represented as a function, with [[function application]] as its only operation. When a continuation object is applied to an argument, the existing continuation is eliminated and the applied continuation is restored in its place, so that the program flow will continue at the point at which the continuation was captured and ''the argument of the continuation'' then becomes the "return value" of the call/cc invocation. Continuations created with call/cc may be called more than once, and even from outside the dynamic extent of the call/cc application. In computer science, making this type of implicit program state visible as an object is termed ''[[Reification (computer science)|reification]]''. ([[Scheme (programming language)|Scheme]] does not syntactically distinguish between applying continuations or functions.) With call/cc a variety of complex control operators can be implemented from other languages via a few lines of code, e.g., [[John McCarthy (computer scientist)|McCarthy]]'s <code>amb</code> [[Operator (computer programming)|operator]] for [[Nondeterministic programming|nondeterministic choice]], [[Prolog]]-style [[backtracking]], [[Simula]] 67-style [[coroutine]]s and generalizations thereof, [[Icon (programming language)|Icon]]-style [[Generator (computer programming)|generator]]s, or [[Engine (computer science)|engine]]s and [[Thread (computing)|thread]]s or even the obscure [[COMEFROM]]{{cn|date=December 2021}}.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)