Talk:Continuation-passing style

message: The material beginning "programming with continuations" to the end of that section seems outside the scope of this article: it is about using continuations as a program control flow mechanism, within a program written largely in direct style, rather than about CPS per-se.
I would suggest that this material be moved to its own page, possibly fleshed out, and that a pointer be made from this page saying something like "continuations are useful in less formal contexts, for instance as ways of passing and manipulating control in a GUI system.
This is called Programming with Continuations.
Any thoughts or objections?
Barak (talk) 12:49, 25 January 2008 (UTC)
thread_title:  Organization and Scope 

message: For people not as familiar with continuations, like me, it might be good to include an example of how to call at least one of the scheme CPS examples.  
For instance, I pasted the factorial example into my scheme interpreter, but I have no idea how to call it so that it prints out 120 as the answer.  ( factorial 5 ??? ) what do I type for the ??? ?
: I added an example about the identity function. But I think the CPS style examples (pyth, factorial) are wrong, because they dont't work. --SteloKim (talk) 06:05, 3 January 2008 (UTC)
replies: text:  I don't find this a very good example.  Instead I will add an example of calling the CPS version of factorial, showing how to interface between code in direct style and code in CPS.  This will also remove the call/cc, which is premature at that point in the article.  However it would be nice to add a section on call/cc in Scheme, or perhaps better a separate article on call/cc and a pointer to it. Barak (talk) 23:50, 14 January 2008 (UTC)
thread_title:  Need an example of how to call 

message: As continuation passing style renders return values virtually useless, it can also be used to eliminate the need for a runtime stack. Several compilers and interpreters for functional programming languages use this ability internally in novel ways.
Can anyone fill this in a bit with examples of specific compilers and/or interpreters that make use of CPS, and which novel ways they do so in? Ari 08:20, 26 December 2005 (UTC)
thread_title:  Examples of compilers that use CPS internally 

message: The article says "CPS is a monad." Can someone please make this clearer with "CPS is a monad because..." or something like that. Toby 21:48, 20 March 2006 (UTC)
replies: text: Ok, I found a paper explaing how it is a monad (or rather how continuations are monads). I'll add it on the "monads in functional programming" page and clarify / correct this sentance when I get back from work later on.--NotQuiteEXPComplete 00:05, 3 August 2006 (UTC)

text: On second though I'll remove this comment since the statement that "CPS is a monad" is wrong. Continuations are monads, but saying this in an article on CPS doesn't make much sense. --NotQuiteEXPComplete 12:52, 3 August 2006 (UTC)
thread_title:  CPS is a monad? 

message: I was looking for an example of CPS-transformation, found none and did it myself. If anyone is interested, here it is ("cps" takes target "k" as second argument):
(defun cps-progn-rec (l k)
  (let ((sym (gensym)))
    (if l
	`(lambda (,sym) ,(cps (car l) (cps-progn-rec (cdr l) k)))
	k)))
(defun cps-progn (l k)
  (if (consp l)
      (caddr (cps-progn-rec l k))
      (cps nil k)))      
(defun cps (expr k)
  (cond
    ((atom expr) `(,k ,expr))  
    ((eql (first expr) 'quote) `(,k ,expr))
    ((eql (first expr) 'lambda)
     `(lambda ,(second expr) ,(cps-progn (cddr expr) k)))
    ((eql (first expr) 'if)
      (let ((test (gensym)))
	(cps (second expr)
	     `(lambda (,test)
		(if ,test
		    ,(cps (third expr) k)
		    ,(cps (fourth expr) k))))))
     (t
      (let* ((args (rest expr))
	     (syms (mapcar (lambda (x) (if (atom x) x (gensym))) args))
	     (result `(,(first expr) ,@syms ,k)))
	(loop
	   as sym in (reverse syms)
	   as arg in (reverse args)
	   do (if (not (atom arg))
		  (setf result (cps arg `(lambda (,sym) ,result)))))
	result))))
C'ya, folks!  —Preceding unsigned comment added by 85.140.198.80 (talk) 05:55, 28 October 2009 (UTC)
thread_title:  Example code 

message: It says (in the "Use and implementation" section): 
      Without first-class functions, techniques such as trampolining of 
      thunk closures can be used; in this case, it is possible to convert 
      tail calls into gotos in a loop, eliminating even the need for TCO.
If you follow the links to "trampolining" "thunk" "closure" they each have many definitions.  This statement is written so generally that it's very hard to understand.  Is this implementing a lazy language in a lowlevel language?  can an example be mustered up?  a citation?  —Preceding unsigned comment added by 99.63.209.53 (talk) 04:41, 10 March 2010 (UTC)
thread_title: Rather Hard to Understand

message: Are you serious???
I'm not an expert in the history of CPS, but I've always been under the impression that it started with Gordon Plotkin's "Call-by-name, call-by-value and the λ-calculus", and I find it rather odd that the history section only mentions the Scheme memo.  —Preceding unsigned comment added by 93.123.21.116 (talk) 07:24, 15 April 2010 (UTC)
thread_title:  No mention of Plotkin? 

message: This line seems curious:
“Functional compilers can also use A-normal form (ANF) (but only for languages requiring eager evaluation)”
AFAIK, there is no necessary connection between ANF and eager evaluation. ANF simply arises as the normal form under administrative reductions performed on the equivalent CPS terms; the fact that it's usually the call-by-value CPS transform that's used isn't really the point.
(Alternatively, GHC has in the past been said to use ANF, though only in the very broad sense of “function arguments are atomic”; I'm pedantic enough to say that's not really ANF.)
I wouldn't dispute that ANF is usually only used for eager languages, but the claim is about suitability.
Luke Maurer (talk) 04:56, 5 October 2016 (UTC)
thread_title:  A-normal form and eager evaluation