Yeah, I am pretty sure I have no choice but trigger an event when the code requests input. I think Python is just much more flexible - you can probably just substitute something that isn't a file for sys.stdin, and when you call getline() on it it just does what it needs to. Flexible dynamic languages and all that. 

That's an interesting way to go about it. Will look into it, maybe. So far I've been browsing the source of GHC.IO.Handle in the hopes of finding a way to do this - maybe use the underlying IORefs in the Handle_ constructor for the Handle data type in order to unsafeCoerce something... I don't even know. I'm beginning to think this is just more or less impossible, though.


On Sun, Jan 5, 2014 at 3:42 PM, Rogan Creswick <creswick@gmail.com> wrote:
On Sun, Jan 5, 2014 at 12:19 PM, Andrew Gibiansky <andrew.gibiansky@gmail.com> wrote:
That's a good idea, but there's no IPython input channel. Instead, the backend (my interpreter) has to *request* input from the frontend, which then supplies this input. The input is entered via a web browser, so there's not even a handle or file descriptor to speak of.

Ugh, so you really do need to trigger an event when the code in the cell requests input.  How does python handle this?

Here's a horrible idea, but in the spirit of brainstorming... you could run the cell code in a separate app (fork off your interpreter), using ptrace (for linux; I'm not sure how to do this on other OSes) to detect system calls that involve stdin, and then supply input based on that.

Aside from being tricky to do for all platforms, that's also going to have a horrible user experience for any code that loops over std in rapidly to get what would otherwise appear as a single input to the user, but I'm grasping at straws...

--Rogan