Ok, I got that working, but don't understand something. Here is the code with two different instantiations of my-frame% - two with the instantiate within a parameterize and two using a let and current-frame call. [I have two to test that it works for multiple frame instances.]<br>
<br>#lang scheme/gui<br><br>(define current-frame<br> (make-parameter #f))<br><br>(define my-frame%<br> (class frame%<br> (super-instantiate ())<br> (field (text-field<br> (instantiate text-field%<br> ("Press test button to update:" this))))<br>
(instantiate button%<br> ("Clear" this)<br> (callback<br> (lambda (b e)<br> (send text-field set-value ""))))<br> (instantiate button%<br> ("Test" this)<br>
(callback<br> (lambda (b e)<br> (update-text-field))))))<br><br>(define (update-text-field)<br> (send (get-field text-field (current-frame))<br> set-value (send (current-frame) get-label)))<br>
<br>(define (call-in-other-eventspace e thunk)<br> (let ([ch (make-channel)])<br> (parameterize ([current-eventspace e])<br> (queue-callback (lambda ()<br> (channel-put ch (thunk)))))<br> (channel-get ch)))<br>
<br>(call-in-other-eventspace<br> (make-eventspace)<br> (lambda ()<br> (parameterize ((current-frame (instantiate my-frame%<br> ("Frame 1"))))<br> (send (current-frame) show #t))))<br>
<br>(call-in-other-eventspace<br> (make-eventspace)<br> (lambda ()<br> (parameterize ((current-frame (instantiate my-frame%<br> ("Frame 2"))))<br> (send (current-frame) show #t))))<br>
<br>(call-in-other-eventspace<br> (make-eventspace)<br> (lambda ()<br> (let ((frame (instantiate my-frame%<br> ("Frame 3"))))<br> (current-frame frame)<br> (send (current-frame) show #t))))<br>
<br>(call-in-other-eventspace<br> (make-eventspace)<br> (lambda ()<br> (let ((frame (instantiate my-frame%<br> ("Frame 4"))))<br> (current-frame frame)<br> (send (current-frame) show #t))))<br>
<br>The last two do exactly what I want. The first two give the effect I was looking for. The first wo give "get-field: expected an object, got #f" when the Test button is clicked. What is the difference?<br>
<br>Doug<br><br>P.S. I'm not sure I would ever have come up with the solution. Thanks for the answer.<br><br><br><div class="gmail_quote">On Tue, Oct 28, 2008 at 6:20 PM, Matthew Flatt <span dir="ltr"><<a href="mailto:mflatt@cs.utah.edu">mflatt@cs.utah.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">At Tue, 28 Oct 2008 12:41:08 -0600, "Doug Williams" wrote:<br>
> I assume the problem is with my mental model of parameters and eventspaces.<br>
> I had assumed that each eventspace would have, in addition to its event<br>
> queues, etc, its own execution thread, and copies of any parameters.<br>
<br>
</div>That's correct.<br>
<div class="Ih2E3d"><br>
> Since<br>
> it allows me to parameterize or set the current-frame in a new eventspace, I<br>
> assume the eventspace 'knows about' my current-frame parameter. What I<br>
> don't understand is why a call to update-text-field by a frame that I think<br>
> is running under 'new' eventspace doesn't get a value for the current-frame<br>
> parameter.<br>
<br>
</div>In<br>
<br>
(parameterize ([current-eventspace E])<br>
B)<br>
<br>
the `parameterize' sets the `current-eventspace' parameter to `E' while<br>
evaluating `B', it still evaluates `B' in the current thread --- not<br>
the handler thread of `E'. So if you mutate a parameter within `B',<br>
then it still mutates the parameter for the current thread, not for the<br>
thread of `E'.<br>
<br>
Use `queue-callback' to jump to another eventspace's handler thread.<br>
The `queue-callback' function uses the `current-eventspace' parameter<br>
(of the current thread) to determine where to queue the callback, and<br>
the callback is invoked in that eventspace's handler thread.<br>
<br>
(define (call-in-other-eventspace e thunk)<br>
(let ([ch (make-channel)])<br>
(parameterize ([current-eventspace e])<br>
(queue-callback (lambda ()<br>
(channel-put ch (thunk)))))<br>
(channel-get ch)))<br>
<br>
<br>
(call-in-other-eventspace<br>
(make-eventspace)<br>
(lambda ()<br>
<div class="Ih2E3d"> (parameterize ((current-frame (instantiate my-frame%<br>
("Frame 2"))))<br>
(send (current-frame) show #t)<br>
</div> (update-text-field))))<br>
<br>
(call-in-other-eventspace<br>
(make-eventspace)<br>
(lambda ()<br>
<div class="Ih2E3d"> (let ((frame-3 (instantiate my-frame%<br>
("Frame 3"))))<br>
(current-frame frame-3)<br>
(send (current-frame) show #t)<br>
</div> (update-text-field))))<br>
<br>
<br>
</blockquote></div><br>