Saturday, April 23, 2005

Reference finder & Laws of Form

So I had written this lovely reference finder by implementing a stream that would traverse the object tree according to whatever criteria, at each step recording its position by means of ReferencePathItems, which could in turn examine an object and tell how many ivars/indexed fields it had, etc.

From that, the reference finder produced a series of "positions" of the stream by means of collecting the current path of reference path items. From that you can collect an array of the objects being streamed over, and that's your reference path.

Since I had implemented Form and Distinction, what I did was to take the path and make a form with distinctions in it representing the path. Thus that beautiful inject:into: piece of code I talked about before.

But when I built a UI on top of it, I realized I did not like something. Forms are basically a set of named things, like a dictionary of names to named objects.

Use the Universal Hint, Luke: never confuse the label with the labeled object.

Exactly, so it's like a dictionary that I chose to implement as a set of associations... I mean distinctions. Each distinction knows its contents (another form with distinctions), and its form (the form where the distinction lives).

Note also that distinctions carry the names, and since we give meaning by using names, then it seems most useful to traverse the distinction graph by holding onto distinctions. Thus, forms seem to have almost no useful purpose to the outside user of forms/distinctions. Then came the question: should I get rid of them?

Then I considered the fantastic messages I had implemented in Form, such as cross: aName. I felt I wasn't grasping something, because crossing a distinction takes you from a form into another one. So why would I want to ditch forms?

I thought maybe it was a problem of traversal. I wanted to hold on to distinctions because the linkage between forms is stored in them. So I thought that I had to implement a stream to traverse the form and my problems would be gone. No more wondering what was the parent of such, etc... so I'd be able to name things and get objects back without worrying what the structure of the form is. Then it hit me.

That's exactly what I did with the reference finder.

Holy cow. This form/distinction stuff is powerful. I mean obviously an object is a distinction and its ivars live in the contents of the distinction etc... but to see how it pervasively takes over is amazing.

So... now that I wasn't happy with the reference finder for other reasons (such as it was remembering having found integers along the way), I find myself in the position of using forms/distinctions to implement a reference finder the results of which I will display on the screen using forms/distinctions in exactly the same way they were used to find references to begin with.

Wow.

No comments: