On Wed, 30 Apr 2003 22:11:26 +0900
Sten Kvamme <skvamme / as4-2-8.an.g.bonet.se> wrote:

> I understand from reading the Ruby documentation that it is easy
> to add a method programmatically to a running object instance, but
> is it also possible to maintain changes (persistance) after system 
> halts?

In fact, you can redefine your entire program while it is live. Once I wrote a text editor using Tk that had this type of dynamic behavior. My first goal was to be able to write the program from within the program and it was pretty easy to accomplish using a text widget and a function that would call an eval function in the main/base class.

The hard part, as you point out, is capturing the changes. There are some possibilities that occurred to me. I was working on my program's actual source code the whole time, so I just saved the file with the changes before using the eval function. This brings up the issue of version control-- you need to keep a safe working copy, while keeping your test copy.

I think as I redevelop that idea using gtk2 I will take the approach of saving the code incrementally. The code is all just text getting sent to eval in a separate eval function. So what I'm thinking now is that each snippet of code would get saved to a file. The files would go in a "delta" directory and follow a sequential naming pattern.

That way you've got all the code that was used to create your program's current state (data aside). Then the main application code just needs a final function right before your main loop or  function call that looks for any "delta" fragments and requires them in the right order. You could also (either by hand or programmatically) merge the deltas back into the original code when it made sense to do so.

 -michael