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
Continuation-passing style
(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!
==Use and implementation== Continuation passing style can be used to implement continuations and control flow operators in a functional language that does not feature first-class [[continuation]]s but does have [[first-class function]]s and [[tail-call optimization]]. Without tail-call optimization, techniques such as [[trampoline (computers)|trampolining]], i.e., using a loop that iteratively invokes [[thunk]]-returning functions, can be used; without first-class functions, it is even possible to convert tail calls into just gotos in such a loop. Writing code in CPS, while not impossible, is often error-prone. There are various translations, usually defined as one- or two-pass conversions of pure [[lambda calculus]], which convert direct style expressions into CPS expressions. Writing in trampolined style, however, is extremely difficult; when used, it is usually the target of some sort of transformation, such as [[compiler|compilation]]. Functions using more than one continuation can be defined to capture various control flow paradigms, for example (in [[Scheme (programming language)|Scheme]]): <syntaxhighlight lang=scheme> (define (/& x y ok err) (=& y 0.0 (lambda (b) (if b (err (list "div by zero!" x y)) (ok (/ x y)))))) </syntaxhighlight> A CPS transform is conceptually a [[Yoneda embedding]].<ref>{{cite report |last1=Stay |first1=Mike |url=http://golem.ph.utexas.edu/category/2008/01/the_continuation_passing_trans.html |title=The Continuation Passing Transform and the Yoneda Embedding}}</ref> It is also similar to the embedding of [[lambda calculus]] in [[π-calculus]].<ref>Mike Stay, [http://golem.ph.utexas.edu/category/2009/09/the_pi_calculus_ii.html "The Pi Calculus II"]</ref><ref>{{cite CiteSeerX |first1=Gérard |last1=Boudol |year=1997 |citeseerx=10.1.1.52.6034 |title=The π-Calculus in Direct Style}}</ref>
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)