Thanks that was a big help but it wasn't quite the solution. I was able to make it run a background process simultaneous to generating my own prompt. But that only solves half my problem: "EditLine readLine" is a blocking call, so it still halts other coroutines while waiting at the "fake Io>" prompt. (Because you can't yield between keypresses.) So it still only executes the background loops once per every time I hit the "return" key on a command in the prompt.
I'm thinking maybe I need something like:
createThread("loop that does readLine for FakeIo> prompt")
@@backgroundCoroutine("do stuff in a loop that yields at the end")
loop(
check for new command from other thread
yield if no new command
doString() if there is a command
)
But how do I get the string data out of the separate VM on the thread that's displaying the FakeIo> prompt and into the original VM that has the backgroundCoroutines and the doString loop? Shared memory? Pipes? Send it to localhost via TCP/IP through a BSD socket??
For the sake of completeness, here's the test code I've got so far: (The idea is the background coroutine increments n every second, while the foreground prompt can change or print n if you type the right command. The fact that the background coroutine picks up on the change and begins incrementing the new value of n proves the foreground prompt changed a variable in the background coroutine.)
n := 1
doBackground := method(
loop("N is " print; n println; n = n + 1; wait(1))
)
doPrompt := method(
s := ""; loop(println; s = EditLine readLine("FakeIo>"); doString(s); yield)
)
@@doBackground
doPrompt
--- In
iolanguage@..., Steve Dekorte <steve@...> wrote:
>
>
> On 2009-06-07, at 9:18 PM, dennisf486 wrote:
> > With the prompt presented by the Io executable, if I type something
> > the prompt goes away until it is done, even if I type something like
> > "o1 @test" to launch a coroutine. Is this a fundamental limitation
> > of Io (can't enter new commands while coroutines are running)? I
> > can think of several approaches; which, if any, are right?
>
> The code that presents the user with the prompt and receives the input
> line can just call doString(theInputString) and I think it should have
> the behavior you are looking for.
>