Introductory definition: SoM: Subtitute or macro
I've been making scorching progress for the last ten days, but I just now had a sodden realization: my wonderful scheme (for setting SoM definitions to immediately precede their calls) falls apart when we consider the possibility of deleting, cutting, or pasting the calls. For example, suppose we have the following code:
Weight[Consequence] <= Affection[ThisActor, ThisSubject]
NewDirObject[Consequence] <= ThisIndObject
alpha <= HistDirObject[ThisCausalEvent]
NewIndObject[Consequence] <= SigOther[alpha]
Now, what happens if the storybuilder deletes SigOther? Now the definition of alpha dangles.
What happens if the storybuilder cuts or copies SigOther, then pastes it over ThisIndObject? Now alpha is called before it is defined.
Oops.
Clearly, I will have to monitor these SoM calls. When we have a straightforward deletion, then it's a simple matter to delete the definition as well, but cut, copy, and paste raise trickier issues. When something is pasted, it creates a second copy of the SoM &emdash; a severe no-no.
Here's a solution. When we cut, we carry out a deletion complete with deletion of the definition. When we copy, we make no change. When we paste, we check for a SoM; if we find one, then we increment the appropriate counter (if the counter overflows, we abort the paste operation) and insert the modified token. This will certainly be messy programming. Nope, this fails on the rock of the circular definition problem. Beta equals something with alpha. Copy the beta call. Paste it above the definition of alpha. Now we have a new SoM, gamma, whose definition includes a call to alpha, that precedes the definition of alpha.
Perhaps we should simply forbid cut or copy of a term containing a SoM. That's awfully artificial, but it would be a lot easier to implement, and this is a rare condition. However, the storybuilder could get confused, finding the cut and copy commands disabled with no explanation. Leaving them enabled with an error message would be nicer, but still clumsy.
Third solution: when a paste is executed, we simply move the definition forward if necessary. This would allow multiple use of SoMs. Nope, this would permit circular definitions.
So it looks as if the only solution is to leave the cut and copy commands enabled, but when they are executed, examine the term for any SoM; if any is found, just pop up an alert that apologizes and explains the problem. It should also suggest a solution. We continue to permit deletion of such terms, with appropriate housekeeping work afterwards. After all, this is a rare enough problem that I shouldn't expend too much effort on it. I suppose so. I am not pleased with this solution.