[racket] Saving and restoring many parameters
On 10/20/2011 08:08 AM, Robby Findler wrote:
> Well, what about the current-namespace? The output ports? It seems
> dangerous and leak introducing (possibly).
>
> I don't actually have an example where it could cause a problem tho. But
> you might try to think thru the ramifications by searing for "current-"
> in the docs.
I still think using a thread wouldn't be a problem. But you convinced me
yesterday that it could become a problem in the future.
So I invented parameter lists. Creating a plot pict looks like this now:
(define saved-parameters (plot-parameters))
(dc (λ (dc x y)
(parameterize/list ([plot-parameters saved-parameters])
(plot/dc renderer-tree dc x y width height ...)))
width height)
Some example tests:
(define p1 (make-parameter 1))
(define p2 (make-parameter 2))
(define ps1 (parameter-list p1 p2))
(check-equal? (ps1) (list 1 2))
(check-equal? (parameterize/list ([ps1 (list 10 20)]) (ps1))
(list 10 20))
(check-equal? (parameterize ([p1 10] [p2 20]) (ps1))
(list 10 20))
(check-equal? (parameterize/list ([ps1 (list 10 20)])
(list (p1) (p2)))
(list 10 20))
(ps1 (list 10 20))
(check-equal? (ps1) (list 10 20))
Rules:
((parameter-list p ...)) = (list (p) ...)
((parameter-list p ...) (list v ...)) = (begin (p v) ...)
(parameterize/list ([(parameter-list p ...) (list v ...)]) e ...)
= (parameterize ([p v] ...) e ...)
((parameter-list* p ... pl)) = (list* (p) ... (pl))
((parameter-list-append pl ...)) = (append (pl) ...)
I know Blake has wanted these before, so I might throw them into unstable.
Neil T