I don't think there is a better way than what you have.
I looked into the undocumented `reparameterize` procedure, from '#%paramz: [
https://github.com/racket/racket/blob/a6eb00a41cc29859424335f40ef9ae68c471c57a/racket/src/racket/src/thread.c#L7680],
but it only copies built-in parameters, so it fails your test case. It
would be easy enough to implement a version that copied the whole
parameterization, but it would have to be implemented in C.


On Tue, Jan 12, 2016 at 9:38 AM, Jos Koot <jos.k...@gmail.com> wrote:

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

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