callcc

scheme continuation inside a for-each

二次信任 提交于 2019-12-02 02:43:34
问题 I'm currently studying Scheme for a course at my university, while looking at some exercises I got stuck on this particular one. Professor has yet to answer my previous mails therefore I have more chances to receive an answer here faster. Given this code (define (list-iter-cc lst) (call/cc (lambda (return) (for-each (lambda (x) (call/cc (lambda (next-step) (return (cons x next-step))))) lst) 'end))) I have to use it to write the iter macro whose syntax is (iter <a variable symbol> in <a list>

scheme continuation inside a for-each

空扰寡人 提交于 2019-12-02 02:11:56
I'm currently studying Scheme for a course at my university, while looking at some exercises I got stuck on this particular one. Professor has yet to answer my previous mails therefore I have more chances to receive an answer here faster. Given this code (define (list-iter-cc lst) (call/cc (lambda (return) (for-each (lambda (x) (call/cc (lambda (next-step) (return (cons x next-step))))) lst) 'end))) I have to use it to write the iter macro whose syntax is (iter <a variable symbol> in <a list> <code>) example: (iter x in '(1 2 3) (display x) (newline)) Since I couldn't understand list-iter-cc i

How to interpret callCC in Haskell?

倖福魔咒の 提交于 2019-12-01 09:16:50
In Scheme executing a continuation obtained from a call/cc effectively jumps back to that initial call/cc and reinstates the saved call stack. I just started learning Haskell and I am trying to figure out how to comprehend callCC . That is try to comprehend callCC in terms of understanding of Scheme's call/cc . The implementation of callCC is callCC f = cont $ \h -> runCont (f (\a -> cont $ \_ -> h a)) h As far as I can tell there is nothing mentioned relating to call stacks saved or reinstated. How does one interpret callCC in Haskell coming from familiarity with Scheme's call/cc . Edit:

How to interpret callCC in Haskell?

若如初见. 提交于 2019-12-01 06:11:02
问题 In Scheme executing a continuation obtained from a call/cc effectively jumps back to that initial call/cc and reinstates the saved call stack. I just started learning Haskell and I am trying to figure out how to comprehend callCC . That is try to comprehend callCC in terms of understanding of Scheme's call/cc . The implementation of callCC is callCC f = cont $ \h -> runCont (f (\a -> cont $ \_ -> h a)) h As far as I can tell there is nothing mentioned relating to call stacks saved or

I just don't get continuations!

冷暖自知 提交于 2019-11-30 10:29:24
问题 What are they and what are they good for? I do not have a CS degree and my background is VB6 -> ASP -> ASP.NET/C#. Can anyone explain it in a clear and concise manner? 回答1: Imagine if every single line in your program was a separate function. Each accepts, as a parameter, the next line/function to execute. Using this model, you can "pause" execution at any line and continue it later. You can also do inventive things like temporarily hop up the execution stack to retrieve a value, or save the

How to make callCC more dynamic?

不羁岁月 提交于 2019-11-30 04:55:27
I thought the right type for ContT should be newtype ContT m a = ContT {runContT :: forall r. (a -> m r) -> m r} and other control operators shift :: Monad m => (forall r. (a -> ContT m r) -> ContT m r) -> ContT m a reset :: Monad m => ContT m a -> ContT m a callCC :: ((a -> (forall r. ContT m r)) -> ContT m a) -> ContT m a Unfortunately, I can not make callCC type check, and don't know how to do it. I managed to make shift and reset type check reset :: Monad m => ContT m a -> ContT m a reset e = ContT $ \ k -> runContT e return >>= k shift :: Monad m => (forall r. (a -> ContT m r) -> ContT m

Can call-with-current-continuation be implemented only with lambdas and closures?

谁说胖子不能爱 提交于 2019-11-30 03:39:11
Does anyone know if call/cc can be implemented with just lambdas and closures? It seems that call/cc interrupts the program's flow (like an exception) but lambdas and closures can't do that. Therefore I think call/cc can't be implemented via lambdas and closures. Any more ideas? The question is not particularly clear, since what exactly does "implemented with just lambdas and closures" mean? In any case, continuations can be used in any language with closures by manually writing in continuation passing style . Then automatic translation into this form can be implemented by extending the

I just don't get continuations!

南笙酒味 提交于 2019-11-29 21:03:19
What are they and what are they good for? I do not have a CS degree and my background is VB6 -> ASP -> ASP.NET/C#. Can anyone explain it in a clear and concise manner? John Millikin Imagine if every single line in your program was a separate function. Each accepts, as a parameter, the next line/function to execute. Using this model, you can "pause" execution at any line and continue it later. You can also do inventive things like temporarily hop up the execution stack to retrieve a value, or save the current execution state to a database to retrieve later. You probably understand them better

How does the yin-yang puzzle work?

╄→尐↘猪︶ㄣ 提交于 2019-11-29 19:33:43
I'm trying to grasp the semantics of call/cc in Scheme, and the Wikipedia page on continuations shows the yin-yang puzzle as an example: (let* ((yin ((lambda (cc) (display #\@) cc) (call-with-current-continuation (lambda (c) c)))) (yang ((lambda (cc) (display #\*) cc) (call-with-current-continuation (lambda (c) c)))) ) (yin yang)) It should output @*@**@***@****@... , but I don't understand why; I'd expect it to output @*@********* ... Can somebody explain in detail why the yin-yang puzzle works the way it works? I don't think I understand this one fully, but I can only think of one (

How to make callCC more dynamic?

假如想象 提交于 2019-11-29 02:02:29
问题 I thought the right type for ContT should be newtype ContT m a = ContT {runContT :: forall r. (a -> m r) -> m r} and other control operators shift :: Monad m => (forall r. (a -> ContT m r) -> ContT m r) -> ContT m a reset :: Monad m => ContT m a -> ContT m a callCC :: ((a -> (forall r. ContT m r)) -> ContT m a) -> ContT m a Unfortunately, I can not make callCC type check, and don't know how to do it. I managed to make shift and reset type check reset :: Monad m => ContT m a -> ContT m a reset