A previous post introduced the <ocaml-eval> function to evaluate ocaml code, enventually displaying the result in a toplevel way, etc.

OCaml code was evaluated in the Stog process, which required Stog to embed the OCaml toplevel, only available as bytecode. As a consequence, only the bytecode version of Stog could evaluate OCaml code using the internal toplevel.

Since release 0.4 of Stog, the evaluation of OCaml has been moved to an external program, ocaml-ocaml-session. This program is launched by Stog when OCaml code has to be evaluated. Stog and this program communicate OCaml values through a pipe (see Stog_ocaml_types module for details).

Of course, an instance of stog-ocaml-session is not launched each time an OCaml phrase has be to evaluated. Instead, Stog keeps a list of "ocaml sessions", each session corresponding to a stog-ocaml-session process.

That allows two cool things:

The default ocaml session is called "default". The session name to use to evaluate OCaml code can be specified using the "session" attribute of <ocaml-eval>.

Here is an example.

let x = 1;;

will give

let x = 1;;

Then, let's evaluate another piece of code, in the same ("default") session:

let y = x + 1;; will give let y = x + 1;;

Now, let's evaluate the same code in another session, "session2":

let y = x + 1;;

will result in

let y = x + 1;;