continuation-passing

Explain the continuation example on p.137 of The Little Schemer

南楼画角 提交于 2019-11-28 05:31:02
The code in question is this: (define multirember&co (lambda (a lat col) (cond ((null? lat) (col (quote ()) (quote ()))) ((eq? (car lat) a) (multirember&co a (cdr lat) (lambda (newlat seen) (col newlat (cons (car lat) seen))))) (else (multirember&co a (cdr lat) (lambda (newlat seen) (col (cons (car lat) newlat) seen)))))) I've stared at this all day but I can't quite seem to understand it. When you recur on the function you are re-defining col but in the examples they seem to use the original definition. Why wouldn't it change. How can you recur on it without passing in the parameters newlat

call-with-current-continuation - state saving concept

蹲街弑〆低调 提交于 2019-11-27 22:31:37
After reading The Seasoned Schemer I felt I understood call/cc properly. But, after seeing some WOW tricks with call/cc I found I was wrong. (define cc 0) (define (f) (call/cc (lambda (k) (set! cc k) 3))) (+ 1 2 4 (f)) ; eval's to 10 (cc 13) ; eval's to 20 That perfectly match my understanding. I think when I reach a call/cc call I am just saving the program state. and calling the function next to it with a function. If that function ( k ) is called from somewhere than I just replacing the entire (call/cc ...) stuff with the parameter given to it. The above program seems to worked that way too

Continuations and for comprehensions — what's the incompatibility?

孤者浪人 提交于 2019-11-27 18:00:02
问题 I am new to Scala and trying to wrap my head around continuations I'm trying to reproduce the yield return C# statement. Following this post, I have written the following code : package com.company.scalatest import scala.util.continuations._; object GenTest { val gen = new Generator[Int] { def produce = { yieldValue(1) yieldValue(2) yieldValue(3) yieldValue(42) } } // Does not compile :( // val gen2 = new Generator[Int] { // def produce = { // var ints = List(1, 2, 3, 42); // // ints.foreach(

How could the new async feature in c# 5.0 be implemented with call/cc?

别来无恙 提交于 2019-11-27 03:59:24
I've been following the new announcement regarding the new async feature that will be in c# 5.0. I have a basic understanding of continuation passing style and of the transformation the new c# compiler makes to code like this snippet from Eric Lippert's post : async void ArchiveDocuments(List<Url> urls) { Task archive = null; for(int i = 0; i < urls.Count; ++i) { var document = await FetchAsync(urls[i]); if (archive != null) await archive; archive = ArchiveAsync(document); } } I know that some languages implement continuations natively, via call-with-current-continuation ( callcc ), but I don

Explain the continuation example on p.137 of The Little Schemer

谁说我不能喝 提交于 2019-11-27 00:47:31
问题 The code in question is this: (define multirember&co (lambda (a lat col) (cond ((null? lat) (col (quote ()) (quote ()))) ((eq? (car lat) a) (multirember&co a (cdr lat) (lambda (newlat seen) (col newlat (cons (car lat) seen))))) (else (multirember&co a (cdr lat) (lambda (newlat seen) (col (cons (car lat) newlat) seen)))))) I've stared at this all day but I can't quite seem to understand it. When you recur on the function you are re-defining col but in the examples they seem to use the original

call-with-current-continuation - state saving concept

坚强是说给别人听的谎言 提交于 2019-11-26 21:01:30
问题 After reading The Seasoned Schemer I felt I understood call/cc properly. But, after seeing some WOW tricks with call/cc I found I was wrong. (define cc 0) (define (f) (call/cc (lambda (k) (set! cc k) 3))) (+ 1 2 4 (f)) ; eval's to 10 (cc 13) ; eval's to 20 That perfectly match my understanding. I think when I reach a call/cc call I am just saving the program state. and calling the function next to it with a function. If that function ( k ) is called from somewhere than I just replacing the

How could the new async feature in c# 5.0 be implemented with call/cc?

两盒软妹~` 提交于 2019-11-26 12:40:48
问题 I\'ve been following the new announcement regarding the new async feature that will be in c# 5.0. I have a basic understanding of continuation passing style and of the transformation the new c# compiler makes to code like this snippet from Eric Lippert\'s post: async void ArchiveDocuments(List<Url> urls) { Task archive = null; for(int i = 0; i < urls.Count; ++i) { var document = await FetchAsync(urls[i]); if (archive != null) await archive; archive = ArchiveAsync(document); } } I know that

What&#39;s the difference between a continuation and a callback?

不羁的心 提交于 2019-11-26 08:39:26
问题 I\'ve been browsing all over the web in search of enlightenment about continuations, and it\'s mind boggling how the simplest of explanations can so utterly confound a JavaScript programmer like myself. This is especially true when most articles explain continuations with code in Scheme or use monads. Now that I finally think I\'ve understood the essence of continuations I wanted to know whether what I do know is actually the truth. If what I think is true is not actually true, then it\'s