[racket] call-with-composable-continuation and DrRacket

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri Aug 31 09:00:21 EDT 2012

Executing code that you calculated out is the right idea. We teach this to our students to check their intuitions. 

To find out where the binding comes from, once again use the macro stepper. It says 
 
>  imported from: "modbeg.rkt" <= racket/private/pre-base

when you click on print-values. But the 'imported' just means that the module-begin macro brought it into scope; it does not mean it is exported from this module for you to import (with regular means). You can easily mimic it with (current-print) though. 

Now don't run this from the def window because then you get its printing again ... 


On Aug 30, 2012, at 10:09 PM, Harry Spier wrote:

> OK I think I grok it.
> 
> When I write in the definitions window of DrRacket
> #lang racket
> (+ 100
>    (call-with-composable-continuation
>    (λ (k) (+  (k 1) 1000))))
> 
> what actually gets executed is at least:
> 
> (call-with-values (+ 100
>    (call-with-composable-continuation
>    (λ (k) (+  (k 1) 1000)))) print-values)
> 
> and the continuation captured by cwcc is at least:
> (λ (x) (call-with-values (lambda () (+ 100 x)) print-values))
> 
> so what gets executed is:
> ((call-with-values
> (+ 100
>    (+ 1000
>       (call-with-values ((λ (x) (+ 100 x)) 1)
>                         print-values)))
> print-values)
> 
> 
> printing out
> 101
> 1201
> 
> When I actually tried to execute this, I got an unbound identifier
> error for print-values and I couldn't find a reference to print-values
> in the racket reference manual.
> 
> Harry Spier
> 
> 
> 
> On Thu, Aug 30, 2012 at 6:11 PM, Matthias Felleisen
> <matthias at ccs.neu.edu> wrote:
>> 
>> On Aug 30, 2012, at 5:48 PM, Harry Spier wrote:
>> 
>>> When I run this in the definitions window of DrRacket
>>> #lang racket
>>> (+ 100
>>>  (call-with-composable-continuation
>>>   (λ (k) (+ 1000 (k 1)))))
>>> 
>>> it prints
>>> 101
>>> 1201
>>> in the interactions window.
>>> Why doesn't it just print 1201 ?
>> 
>> 
>> As John says, the meaning of this program isn't "on its sleeve" as semanticists used to say in the 1980s. If you use the Macro Stepper to expand the above program (- racket, -library), you get
>> 
>> (module anonymous-module racket
>>  (#%module-begin
>>   (#%app
>>    call-with-values
>>    (lambda ()
>>      (#%app
>>       +
>>       (quote 100)
>>       (#%app call-with-composable-continuation (lambda (k) (#%app + (quote 1000) (#%app k (quote 1)))))))
>>    print-values)))
>> 
>> The key is to note that an expression is wrapped in a (call-with-values . print-values), plus an outer #%module-begin. Hence the meaning of cwcc is (at least)
>> 
>> (lambda (x) (call-with-values (lambda () (+ 100 x)) print-values))
>> 
>> ;; ---
>> 
>> In contrast, the same expression in the repl gets expanded via #%top, which does not wrap the print-values around it -- after all the "printer" is a part of the REPL.
>> 
>> ;; ---
>> 
>> Perhaps this is somewhat ironic, because the idea is really that each expression in the def window should be wrapped in a "prompt" -- but it means only "control delimiter". Something to consider is that we take the meaning of the word "prompt" literally and have the two areas behave identically.
>> 
>> -- Matthias
>> 
>> 
>> 
>> 
> 
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4373 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20120831/6fde39ea/attachment.p7s>

Posted on the users mailing list.