Shortcut to automatize a few actions (terminal reopening after recompilation)

I use a terminal-centered style of OCaml development.
My loop is thus as follows :

→ Experiment in the terminal
→ edit the “official” files in the project, recompile
→ close the terminal and reopen another (since the old terminal
does not know about the new cmos/cmis etc. One might try to get around this by reloading some cmos from the old terminal, and it might work in some very simple cases, but it definitely breaks down when a type’s definition is changed, especially when it is used in other modules).

For me, those last steps consists of the following :

  • call a function of mine called recompile with a string argument describing the update made before recompiling
  • Ctrl+D to close the terminal
  • utop to reopen another.

It would be really nice to be able to execute all this in one single command.
I have a feeling this is definitely doable but far above my paygrade in Unix advanced tools.
I am thinking of something like this : an executable that would get called from utop, the executable would find out the PID of the terminal process that called it, closed it and reopen a new terminal ?