RE: [racket-users] Calling a procedure without allowing it to permanently alter parameters.

2016-01-13 Thread Jos Koot
Jon and Jon,
Both thanks for your replies.
I'll stick to call-in-nested-thread.
Jos

  _  

From: Jon Zeppieri [mailto:zeppi...@gmail.com] 
Sent: miércoles, 13 de enero de 2016 6:03
To: Jos Koot
Cc: Racket Users
Subject: Re: [racket-users] Calling a procedure without allowing it to
permanently alter parameters.


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/a6eb00a41cc29859424335f40ef9ae68c471c
57a/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  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.


Re: [racket-users] Calling a procedure without allowing it to permanently alter parameters.

2016-01-12 Thread Jon Zeppieri
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  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.


Re: [racket-users] Calling a procedure without allowing it to permanently alter parameters.

2016-01-12 Thread jon stenerson
I see. Then, I'm sorry to say, I have no idea other than what you 
already suggested.


On 1/12/2016 6:08 PM, Jos Koot wrote:

Your suggestion works,
but only for explicitly parameterized parameters.
There may be parameters that I don't know of,
but nevertheless may affect my protected-caller.
Therefore I want ALL parameters protected.
Thanks, Jos

-Original Message-
From: racket-users@googlegroups.com [mailto:racket-users@googlegroups.com]
On Behalf Of jon stenerson
Sent: miércoles, 13 de enero de 2016 0:50
To: racket-users@googlegroups.com
Subject: Re: [racket-users] Calling a procedure without allowing it to
permanently alter parameters.

Can you use this instead?

(define (protected-caller thunk)
(parameterize ([p 'anything])
  (thunk)))

Works for me

Jon



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


RE: [racket-users] Calling a procedure without allowing it to permanently alter parameters.

2016-01-12 Thread Jos Koot
Your suggestion works,
but only for explicitly parameterized parameters.
There may be parameters that I don't know of,
but nevertheless may affect my protected-caller.
Therefore I want ALL parameters protected.
Thanks, Jos

-Original Message-
From: racket-users@googlegroups.com [mailto:racket-users@googlegroups.com]
On Behalf Of jon stenerson
Sent: miércoles, 13 de enero de 2016 0:50
To: racket-users@googlegroups.com
Subject: Re: [racket-users] Calling a procedure without allowing it to
permanently alter parameters.

Can you use this instead?

(define (protected-caller thunk)
   (parameterize ([p 'anything])
 (thunk)))

Works for me

Jon

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


Re: [racket-users] Calling a procedure without allowing it to permanently alter parameters.

2016-01-12 Thread jon stenerson

Can you use this instead?

(define (protected-caller thunk)
  (parameterize ([p 'anything])
(thunk)))

Works for me

Jon

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