[racket] call-with-composable-continuation and DrRacket
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
>
>
>
>