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

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Aug 30 18:11:58 EDT 2012

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




-------------- 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/20120830/d9297a13/attachment.p7s>

Posted on the users mailing list.