[plt-scheme] Repl during animation or simulation

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Wed Jun 3 21:51:08 EDT 2009

Greg Santucci wrote:
> Does PLT Scheme support using the REPL during program execution? During a
> simulation, I'd like to change parameters or function definitions at
> runtime.

Do you mean you want to affect a long-running program during its 
execution? That is, as opposed to a series of shorter interactions where 
you run, change parameters and definitions, run again, change again, and 
so on.

If so, there are two ways to do it. If there are fixed points at which 
you want to change things, you can actually have your program ask for 
input at those points. You can use 'read' or a similar function to get 
input and interpret it yourself, or you can call 'read-eval-print-loop' 
to start up a REPL that will return to your program when it's finished. 
(In that case, you might want to set up the 'exit-handler' parameter so 
that calling 'exit' quits the REPL.)

The alternative is to create a separate thread for your program's 
execution. While it's running in the other thread, you can execute 
commands in the REPL that change its behavior. PLT Scheme has many 
options for managing concurrency and communication, from semaphores to 
channels (synchronous and asynchronous) and synchronizable events.

Be aware, if you take the concurrent approach, that parameters (as in 
'make-parameter') are like thread-local storage. You won't be able to 
affect your program running in thread B by changing the parameter values 
through the REPL in thread A.


Posted on the users mailing list.