Well, what about the current-namespace? The output ports? It seems dangerous and leak introducing (possibly). <br><br>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. <br>
<br>Robby<br><br>On Tuesday, October 18, 2011, Neil Toronto <<a href="mailto:neil.toronto@gmail.com">neil.toronto@gmail.com</a>> wrote:<br>> I hear you. If I used any parameters except the plot ones, I'd have a problem, and write macros as you suggest. (Or save and restore the exceptions instead.) For now, I'm trying Matthew's suggestion, and using this:<br>
><br>> (define (parameterize-procedure t)<br>> (define parameterization (current-parameterization))<br>> (make-keyword-procedure<br>> (lambda (kws kw-args . rest)<br>> (call-with-parameterization<br>
> parameterization<br>> (lambda () (keyword-apply t kws kw-args rest))))))<br>><br>> In plot-pict, it looks like<br>><br>> (dc (parameterize-procedure<br>> (lambda (the-dc x y)<br>
> (plot/dc ... the-dc x y ...)) ...))<br>><br>> It seems to work just fine. *crosses fingers* There may be some parameters that slideshow uses that I'm not aware of, though...<br>><br>> But I think I *want* to save every parameter value. If a user plots a function that uses a parameter, I want the function to use the value as it was on the call to 'plot-pict', not its value later.<br>
><br>> Neil T<br>><br>> On 10/18/2011 01:48 PM, Robby Findler wrote:<br>>><br>>> There are parameterizations, but they pick up all parameters and that<br>>> may make other things go wrong (or you have to be more careful how you<br>
>> look up your parameter values but I think you might object to that on<br>>> similar grounds to the below).<br>>><br>>> I would probably use the solution you have below, but with some macro<br>>> help. Specifically, in the place where you define all those paramters,<br>
>> use a macro to define them, and then have other macros that<br>>> collaborate with the defining macros to capture and restore the<br>>> parameter values.<br>>><br>>> Robby<br>>><br>>> On Tue, Oct 18, 2011 at 2:40 PM, Neil Toronto<<a href="mailto:neil.toronto@gmail.com">neil.toronto@gmail.com</a>> wrote:<br>
>>><br>>>> Executive summary: Is there a good way to save a large set of parameter<br>>>> values, or *all* the parameter values, and then restore them when needed?<br>>>><br>>>> In the new PLoT, much of a plot's appearance is controlled by parameters. I<br>
>>> use parameters because there are so many appearance-controlling values that<br>>>> passing them into the plot area as arguments would get silly very quickly. I<br>>>> dislike functions with 20 arguments, and I *really* dislike duplicating all<br>
>>> those arguments in every function in a call chain. Parameters are a perfect<br>>>> remedy.<br>>>><br>>>> There's one problem, though: to produce a slideshow pict of a plot, I need<br>
>>> to do this:<br>>>><br>>>> (dc (lambda (the-dc x y)<br>>>> (plot/dc ... the-dc x y ...)) ...)<br>>>><br>>>> where 'plot/dc' draws a plot on a device context. Because the call to<br>
>>> 'plot/dc' is in a thunk, it gets the *current* parameter values, which is<br>>>> very wrong. That makes it impossible to, for example, change the background<br>>>> color of only one plot in a slideshow by doing<br>
>>><br>>>> (parameterize ([plot-background "red"])<br>>>> (plot-pict ...))<br>>>><br>>>> The problem is that the pict returned by 'dc' calls the drawing thunk<br>
>>> *after* the dynamic scope in which 'plot-background' is "red".<br>>>><br>>>> To fix the problem, I'm doing this:<br>>>><br>>>> (define foreground (plot-foreground))<br>
>>> (define background (plot-background))<br>>>> (define foreground-alpha (plot-foreground-alpha))<br>>>> (define background-alpha (plot-background-alpha))<br>>>> (define font-size (plot-font-size))<br>
>>> ...<br>>>> (define animating? (plot-animating?))<br>>>><br>>>> (dc (lambda (the-dc x y)<br>>>> (parameterize ([plot-foreground foreground]<br>>>> [plot-background background]<br>
>>> [plot-foreground-alpha foreground-alpha]<br>>>> [plot-background-alpha background-alpha]<br>>>> [plot-font-size font-size]<br>
>>> ...<br>>>> [plot-animating? animating?])<br>>>> (plot/dc ... the-dc x y ...))) ...)<br>>>><br>>>> Besides looking evil, it's barely maintainable. Every time I add an<br>
>>> appearance-controlling parameter, I have to remember to add it to the above<br>>>> incantation. (Actually, there are two.)<br>>>><br>>>> I've had a similar problem with the click-and-drag-to-rotate 3D plots.<br>
>>> Because I was already using threads for that, I just made sure the render<br>>>> thread is always (transitively) a child of the thread in which the call to<br>>>> 'plot3d' was made. It therefore inherits the original parameter values.<br>
>>><br>>>> So I can use threads to save parameter values. I could make a render thread<br>>>> to solve my 'plot-pict' problem. But is there a better way?<br>>>><br>>>> Neil T<br>
>>> _________________________________________________<br>>>> For list-related administrative tasks:<br>>>> <a href="http://lists.racket-lang.org/listinfo/users">http://lists.racket-lang.org/listinfo/users</a><br>
>>><br>><br>>