Yay!

A caveat: I've never touched iOS, but some event-based systems will not call back unless an event for which you have registered is triggered.  In games, where you redraw the whole screen many times per second this is not a problem, since the 'draw' callbacks should give plenty of opportunity for Scheme land code to run.  But in a more static GUI application this might not be the case.  It could be that the REPL freezes until the user interacts with the app window in some way.  Hence the suggestion for timer or idle handlers.


On Fri, Aug 8, 2014 at 11:56 AM, Álvaro Castro-Castilla <alvaro.castro.castilla@gmail.com> wrote:

On Fri, Aug 8, 2014 at 1:19 AM, Estevo <euccastro@gmail.com> wrote:
One thing I'd try would be to launch a gambit thread running ##repl-debug-main and set up a timer or idle handler in the main gambit thread that just 'thread-sleep!'s for a small amount of time.  Hopefully experimentation yields a delay that is small enough to be unnoticeable in your application, but large enough to give the REPL enough time to do its work.  If you use a timer for this (or, I imagine, if you handle timers in Gambit at all), the trick to run it in the same OS thread would be required.  I don't know, from the top of my head, whether and how SDL does idle events.

A fancier approach would be to look up the implementation of ##repl-debug-main and try and see if there are any hooks by which the trick I mentioned in the previous message could be enabled.  If there are not, you could try running your own modified version of ##repl-debug-main (factoring out the hooks that would enable the just-wait-for-as-long-as-the-REPL-is-doing-actual-work trick would be a nice contribution to gambit IMHO).


Thanks all for your insights and help :)

I found a solution, which is very simple: just create the REPL thread, then create the SDL Cocoa draw loop callback, and finally let the main function return. Since the callback is going to be called repeatedly by iOS, the REPL thread will be resumed since it didn't terminate. The key insight is realizing that the current thread in Scheme returns to C, but the other threads will continue their execution as soon as you come back to Scheme.

It works now, with both custom application loops and event-loop hooks models.