OCamlPro / ocaml-top

A simple cross-platform OCaml code editor built for top-level evaluation.
http://typerex.org/ocaml-top.html
GNU General Public License v3.0
64 stars 8 forks source link

How does one use "read_int()"? #45

Open brabalan opened 11 years ago

brabalan commented 11 years ago

I have a lab session where the students need to enter some data. Before, we were using "read_int()" for that, but in ocaml_top it seems to hang, waiting for the input.

Is there a way to give some input to a program? Maybe by opening a dialog box?

AltGr commented 11 years ago

That's a difficult question.

It would be problematic to allow one to send the input directly to the stdin of ocaml (which is where read_int() reads from), because this is the same channel that is used to send it the source code, and there is no easy way to delimit different kinds of input (ie ocaml-top has no way to know that it's your script reading an int and not the ocaml toplevel). Using different inputs, or a socket, could help, but we want ocaml-top to remain compatible with any external top-level.

So re-defining read_* functions to trigger a different means of input sounds like the way to go ; we already redefine output functions anyway (so that your program's output and ocaml's can be recognized). I'll see what can be done; opening a dialog box would be nice but requires a GUI lib to be available from the toplevel so that will be difficult to keep portable.

ghost commented 8 years ago

Hello, basically, in your console, if you type let x = read_int();; , you will be prompted for input. If you enter an integer, then, the value of x will become the value you entered.