Hi,

I am currently building an iOS app with Gambit and I (of course) need a REPL-server in it so I can develop interactively instead of recompiling the app every time I make a change.
I saw the REPL-server that Marc developed in the iOS example folder of Gambit distribution so I tried to integrate it in my app. I was able to make it work but I have some problems.

When I first tried it I tried to run the repl server in a separate gambit thread. I therefore defined the following: 

(c-define (init-repl-server) () void "initREPLServer" ""
  ; Start a REPL server 
  (thread-start!
    (make-thread
      (lambda ()
        (display "\n\nStarting REPL server on port 7000\n")
        (repl-server-start "toto")))))


In the objective-c method (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
I called the gambit setup and then the initREPLServer();  function.

This didn't work: when the C function returned the Gambit thread died (this is my interpretation) and I could not connect to the server.

I therefore tried put an infinite-loop at the end of the (init-repl-server) function. It worked but the app would not finish the startup process since "application didFinishLaunchingWithOptions"
call never returns YES as expected.

I then tried to run the scheme program in a separate thread (in that thread the call to (init-repl-server) in C would not have to return and would keep running). 
    [NSThread detachNewThreadSelector:@selector(initReplServer) toTarget:self withObject:nil];
I could then connect to the repl server but all assignments in objects are ignored by the interface loop since they are done in a separate thread. I then had the idea to use objective-c blocks (kind of closures in the objective-c world). 

[[NSOperationQueue mainQueue] addOperationWithBlock:^{ object.slot=value; }];
                                 
This worked.... All the updates were now done in the GUI while working in the remote REPL. One day I tried to instantiate a UIWebView and the app crashed. UIWebView only works in the "main" thread.

I don't like the idea to have the REPL-server and Scheme program in a separate thread. So I tried to put just the REPL-server in a separate thread and run my actual scheme program in the main thread.
In this setup I could connect to the remote REPL but all the variables in the Scheme world are not pointing to the right memory location so everything is scrambled. 

Is there a way out of this...? Can my program run in the main thread while still having a working remote REPL to debug it? 


Thank you,
Francois Magnan