Well, after much travail I have completed the change in the file structure, moving all token strings to the role structure, rather than leaving some in the individual consequence structures. What a pain that was! But now I'm moving back to the editing issues, and one of these days I'll be able to get back to work on the substitution variables. Remember substitution variables? That's what started this whole trip.
Anyway, the issue for now is the precise handling of replacements during editing. Here's the user with an operator selected. If the user designates a new operator from the menus, what happens?
The simplest solution, we all know, is to delete the selected operator and all its arguements and replace it with the new operator and an arguement list of unspecified terms. This is certainly easy enough to program. But I continue to balk at so extreme a solution. It would certainly waste a lot of effort. Isn't there any way that we can preserve the user's previous work intelligently?
Let's tackle this by instances. I'll use the following notation: PA means "previous operator's arguement count" and NA means "new operator's arguement count". Here are some representative cases:
PA = 0 and NA = 0. This is trivial: we perform a dumb replacement and everybody's happy. Nothing is lost, so there's no cause for complaint.
PA = 0 and NA > 0. In this case, it might be useful to wrap PA inside of NA. Example: PA = "27". NA = "+". Is the user indicating that she wants to add something to 27, or that she wants to get rid of the 27 completely? If that were the case, she'd delete 27, right?
PA > 0 and NA = 0. This is another simple case. Clearly, the user doesn't want to preserve old arguements, so we delete everything associated with PA and use NA directly.
PA > 0 and NA > 0 and PA > NA. OK, now we're getting trickier. I think that the solution here is to delete all of PA and put in just NA.
PA > 0 and NA > 0 and PA < NA. This is another case where it might be useful to wrap PA inside NA. But there's a serious ambiguity here: does PA itself go inside of NA, or do its arguements go inside NA? Hoo boy.
OK, we have a useful discriminator here: the previous operator and its arguements. Either we incorporate the arguements or the operator: which should it be? It seems to me that, if we are to incorporate the arguements, there is just too much complexity, but if we are to incorporate only the operator itself (including, of course, its already-specified arguements), then it could fit quite well.
This raises another issue, though: data typing. Do we want to say that any value can go inside any arguement? Do we want to create certain arguement types and then use typing to discriminate between the various possibilities?
I think that we can leave off data typing for now. After all, the substitution variables are going to really screw that up further down the road.
OK, so that leaves us with the possibility of inserting the old operator inside the new operator, but only if it takes any arguements. But what if there are two or more arguements &emdash; where would the old operator go? I can see all sorts of ugly possibilities here. The user meant it to go in the second position, but it went into the first; or vice versa. Either way, we end up pretty screwy.
For now, the solution has to be the brutal one: delete the old operator. However, at some point in the future, I'd like to consider a more enlightened possibility.