Thank Joao

I change my code like this:

#lang racket


((lambda ()
   
  (define saved-k #f)

  (println (+ 1 (call/cc
        (lambda (k) ; k is the captured continuation
          (set! saved-k k)
          0))))

  (println 'hello)

  (saved-k 100)


  ))

Now it works as I expected.

But why?

"begin" special form packages a sequence of expressions into a single 
expression. After compiled, it should be continuation-passing style.

"lambda" special form also have a sequence of expressions in it.

They are essentially the same, except the lambda can be applied.

What is prompt you mentioned?

I have not heard of this concept before.

Can you tell me something about the prompt?

Thanks.

On Friday, October 26, 2018 at 12:40:37 AM UTC+8, Joao Pedro Abreu De Souza 
wrote:
>
> Well, call/cc is like (in racket) delimited continuation, and have a 
> implicit prompt around a s-exp, so, as begin is a macro, he don't create a 
> prompt. The continuation captured is (+ 1 []) in your example.
>
> If you change the begin to a let, this works, because let expand to a 
> application of a lambda, so create prompt as you expected
>
> Em quinta-feira, 25 de outubro de 2018, <serioa...@gmail.com <javascript:>> 
> escreveu:
>
>> Dear all,
>>
>> I am learning call/cc in racket, so I wrote some experiment code:
>>
>> #lang racket
>>
>> (begin
>>
>>   (define saved-k #f)
>>
>>   (+ 1 (call/cc
>>         (lambda (k) ; k is the captured continuation
>>           (set! saved-k k)
>>           0)))
>>
>>   (println 'hello)
>>
>>   (saved-k 100)
>>
>>   ;; why 'hello not print more than once??
>>  
>>   )
>>
>> The execution result of this codeis:
>>
>> 1
>> hello
>> 101
>>
>>
>> It does not meet my expectation, my expectation is :
>>
>>
>> 1
>> hello
>> 101
>> hello
>> 101
>> ....loop
>>
>>
>> About continuation, for example:
>>
>> assume  exp1 is:
>> (+ 1 (call/cc
>>         (lambda (k) ; k is the captured continuation
>>           (set! saved-k k)
>>           0)))
>>
>> exp2 is:
>> (println 'hello)
>>
>> Whether exp2 is the continuation of exp1
>>
>> Are these two expressions equivalent?
>>
>> (begin
>>   (exp1)
>>   (exp2))
>>
>>
>> (exp1 (lambda (v)
>>         (exp2 continuation-of-exp2)))
>>
>>
>> So exp2 is exp1's continuation?
>>
>> It makes me confused.
>>
>> Excuse me, this question may be stupid, forgive my ignorance...
>>
>> Thanks.
>>
>> Br,
>> serioadamo97
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to