[racket] Parameters and servlets

From: Neil Toronto (neil.toronto at gmail.com)
Date: Wed Jan 22 18:05:07 EST 2014

On 01/22/2014 11:56 AM, Jay McCarthy wrote:
> On Tue, Jan 21, 2014 at 11:03 AM, antoine <antoine.brand at sfr.fr> wrote:
>> Bonjour,
>>
>> I think the parameterize approach didn't work because of:
>>
>> (parameterize ([request-data (extract-the-data req)])
>>                (responce/output (lambda (out) (request-data))))
>>
>> The lambda is put into a response struct, and the call to this
>> lambda is done outside the scope of the parameterize.
>
> You could do something like this:
>
> (define-syntax-rule
>    (paramda args . body)
>    (let ([the-params (current-parameterization)])
>      (lambda args
>        (call-with-parameterization
>         the-params
>         (λ () . body)))))
>
> (paramda (out) (request-data))
>
> This way, whenever the lambda is eventually called, it will be called
> using the same parameters as when it was created.

Another option is to use `unstable/parameter-group', to define, save, 
and restore a group of parameters. This would give you complete control 
over which parameters you save and restore. The plot library does this 
in plot snips to ensure that their rendering threads have the same 
parameter values as the main thread that created the plots.

It could be safer, too. You wouldn't end up saving and restoring 
parameters like `current-custodian', `current-thread' and 
`current-eventspace', for example. (I don't know how dangerous that is, 
but it seems dangerous.)

I've never tested how fast it is vs. `call-with-parameterization', but 
it's about the same speed as saving and restoring the parameters 
individually.

Neil ⊥


Posted on the users mailing list.