Like Zarf says, it’s not possible with a Z-machine backend, because the running program can only modify a small part of the memory map. I don’t know about Glulx, but I trust Zarf’s expertise on the matter.
With a generic backend, like jkj yuio suggested, things are more flexible. The idea of iterative IF development is quite attractive. When I was writing my own game, I often had to navigate through the first part of the game just to check something towards the end, only to find that it wasn’t quite fixed yet.
At one point during the development of Dialog, it was actually possible to put in queries, e.g. “(enter #library)”, directly at the game prompt. A nifty feature, but it caused all kinds of trouble for the optimizing compiler, so I had to scrap it, since generating optimized code was one of my explicit design goals.
An interactive debugger or IDE, with a custom backend, would have access to the complete source code. It would be expected to run on modern hardware, so the performance constraints are relaxed. This would remove the technical roadblocks.
But there’s another snag: In a traditional REPL, the programmer adds or replaces functions, which are maintained in a set. But in Dialog, the order of rules is significant. So when adding a rule, one would have to specify where in the program the rule should appear. It seems more natural, then, to have an editable source-code pane next to a pane with a running game. But there’s still room for innovation: What if the current game state is tracked using high-level constructs in the debugger, and modifications to the source code don’t reset this state. Then it should be possible to modify the rules and messages of the program/library, while still retaining all of the state of the running game (including current room and inventory). From time to time, it would still be necessary to replay all commands, just to verify that nothing has broken elsewhere in the game. But it should shorten the dev-cycle, which I think is what this feature request ultimately boils down to.
It’s long term, sure, but if I’m going to make an IDE at some point anyway, this does seem like a killer feature to have. And it’s one that has to be designed-in from the start, so thanks for bringing it up!