#|
Hi,
Consider a procedure, say protected-caller,
that accepts a thunk and calls it,
but does not want any parameter or handler to be altered by the thunk.
Of course the called thunk can alter parameters and handlers for its own
use,
but I want all parameters and handlers reset after return from the thunk.
First I tried to accomplish this with
current-parameterization and call-with-parameterization,
but did not find a way out.
Now I use call-in-nested-thread to fullfil my wish,
which works well, I think. I did this as shown below.
Is this the correct way to do what I want?
May be it is expensive with respect to cpu time,
but in my case this is not an important issue.
 
Don't bother about the continuation-barrier.
It is there because I don't allow the called thunk
to escape from the dynamic range of procedure protected-caller.
 
The code shown below is a simplification of my original code.
|#
 
#lang racket
 
(define (protected-caller thunk)
 #;"some things to do not shown here."
 (call-with-continuation-barrier
  (λ () (call-in-nested-thread thunk)))
 #;"more things to do not shown here.")
 
(define p (make-parameter 1))
 
(protected-caller (λ () (p 2) (p))) ; -> 2 ; as I wish.
 
(p) ; -> 1 ; as I wish.
 
; Best wishes, Jos
 

-- 
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