About (+ 1 (prompt (* 2 (call/cc (lambda (k) (set! x k) 2)))))

1. "prompt" form does not exist in racket. 
It is a procedure application or special form ?

2. assume this procedure or special form exists to construct a prompt.

(+ 1 (prompt (* 2 (call/cc (lambda (k) (set! x k) 2)))))

After the (lambda (k) ...) evaluated, value of k is (* 2 []), then I call
(k 0) ; <---- When does the control flow come back here?

(k 0) ---jump to--> (* 2 []), and then?

What happens after (*2 0) ? What is the continuation of (*2 0)?


On Friday, October 26, 2018 at 2:11:43 AM UTC+8, Joao Pedro Abreu De Souza 
wrote:
>
> well, let's go by parts :
>
> 1) call/cc in principle will capture the complete continuation of a 
> expression, right? Delimited continuation will capture ... welll, delimited 
> continuations. But delimited by what? By a prompt.
> In a delimited contninuation style(not really, but I dont want to mix 
> functions), we will do something like (+ 1 (prompt (* 2 (call/cc (lambda 
> (k) (set! x k) 2)))))
>
> this will set x with (* 2 []), because delimited capture from prompt.  
> call/cc in racket works in a similar way, if around the most extern s-exp 
> exists a prompt.
>
> 2) well, when I dont know exactly why begin dont work and lambda do, but I 
> have a clue : if you do (syntax->datum (expand '(begin (print "hi") (print 
> "hello")))) in drracket, you will receive
> '(begin (#%app print '"hi") (#%app print '"hello"))
>
> and if you do (syntax->datum (expand '((lambda () (print "hi") (print 
> "hello"))))) you will receive '(#%app (lambda () (#%app print '"hi") (#%app 
> print '"hello")))
>
> Probably, as begin dont is involved in a #%app, he dont is invoked with a 
> prompt. But this is just speculation of my part.
>
> Em qui, 25 de out de 2018 às 14:13, <serioa...@gmail.com <javascript:>> 
> escreveu:
>
>> 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> 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.
>>>> 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...@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