In that other thread, the crux of the issue seems to be:
I wondered if you’ve given org-babel a try. It’s somewhat similar to writing code blocks in MDX, in the sense that you can have a toplevel session that spans blocks (or not, if you prefer).
A simple example:
.emacs settings:
(org-babel-do-load-languages
'org-babel-load-languages
'((ocaml . t)))
; better ergonomics, but only for trusted code blocks!
(setq org-confirm-babel-evaluate nil)
babel-example.org:
#+begin_src ocaml
let x = 3
#+end_src
#+RESULTS:
: 3
#+begin_src ocaml
let y = x + 1
#+end_src
#+RESULTS:
: 4
The initial version of this buffer contained only the #+begin_src...#+end_src blocks, and the results were generated automatically and sequentially in response to C-c C-v C-b. It may not be desirable that later calls to this command reuse the session, but there are workarounds for that.