[racket] how does call/cc and let/ec exactly works?

148 views
Skip to first unread message

김태윤

unread,
Oct 18, 2010, 6:41:11 AM10/18/10
to us...@racket-lang.org
hello 
I am thinking of such a code like..
#lang scheme
(require racket/gui)
(let ([v (let/ec out
               (dynamic-wind
                (lambda () (display "in "))
                (lambda ()
                  (display "pre ")
                  (display (call/cc out))
                  #f)
                (lambda () (display "out "))))])
      (when v (v "post ")))

but I still have no idea how 
"in pre out in post out " is printed but not "in pre out in pre post out "
how does call/cc and let/ec exactly works?

김태윤

unread,
Oct 18, 2010, 8:50:14 AM10/18/10
to us...@racket-lang.org
thank you for your replying
does call/cc always working with let/ec?
when it comes to compare with your code, it looks like..
call/cc is meaning of "get out of this function and evaluate next function and comeback (to inside of let/ec) for evaluate rest of the code"
is it right?

if so, I don't understand why 

following code does not working properly
#lang scheme

(require racket/gui)

(define (aa) #t #f "11")

(dynamic-wind
 (lambda () (display "in "))
 (lambda ()
   (display "pre ")
   (let/ec out
     
     (display (call/cc out)))
   (display "1")
   (display "2")
   (display "3")
   )
 (lambda () (display "out ")))

but the following code works weird
#lang scheme
(require racket/gui)
(define (aa) #t #f "11")
(dynamic-wind
 (lambda () (display "in "))
 (lambda ()
   (display "pre ")
   (let/ec out
     (display (call/cc out)))
   (display "1")
   (display "2")
   (display "3")
   "1")
 (lambda () (display "out ")))


2010년 10월 18일 오후 7:59, Jos Koot <jos....@telefonica.net>님의 말:
Compare yoiur code with:
 
#lang scheme

(require racket/gui)

(dynamic-wind
 (lambda () (display "in "))
 (lambda ()
   (display "pre ")
   (let/ec out

     (display (call/cc out)))

   #f)
 (lambda () (display "out ")))
 
Jos


From: users-...@racket-lang.org [mailto:users-...@racket-lang.org] On Behalf Of ???
Sent: 18 October 2010 12:41
To: us...@racket-lang.org
Subject: [racket] how does call/cc and let/ec exactly works?

Jens Axel Søgaard

unread,
Oct 18, 2010, 8:59:35 AM10/18/10
to 김태윤, us...@racket-lang.org
2010/10/18 김태윤 <kty...@gmail.com>:

> how does call/cc and let/ec exactly works?

Read

http://www.cs.indiana.edu/hyplan/dfried/appcont.pdf

--
Jens Axel Søgaard
_________________________________________________
For list-related administrative tasks:
http://lists.racket-lang.org/listinfo/users

Reply all
Reply to author
Forward
0 new messages