Traversals

Now that we know the basics of messaging, such as naming selectors properly and using Polymorphism to cross distinctions drawn by means of classes, it is time to use what we have just discussed to implement `matches:` in a completely new way.

First of all, if we are going to let a behavior traverse an information space to answer the question `aPattern matches: aString`, what is the space we are talking about? And given the space, what does asking `matches:` represent?

We can try to guess the space by looking at the static context of matches:. In our non-inlined version, the static context was represented by the instance names of the match tracker. These names kept the positions up to which the pattern had matched the string, and the positions up to which the string had been examined according to the pattern. In other words, the static context of matches: seemed to be as follows.

* aPattern, patternMatchedInterval

* aString, stringMatchedInterval

If the static context above represents the location in the information space, then what is the direction of the traversal implied by `matches:`? Well, it seems to be going from a location (or static context) of non-empty intervals towards one in which the intervals are empty. Thus, if that is the case, the matter of `matches:` appears to imply two issues that need to be addressed. The first one is do both intervals become empty at the same time? The answer to this question is the value of `matches:` — assuming the traversal can be performed in the first place! Clearly, the traversal ’abc’ `matches:` ’xyz’ will not get anywhere. Therefore, the second issue is *can the traversal reach a point in which at least one of the intervals is empty?*

We can put those two questions together. Thus, in simpler terms, the value of matches: is the answer to the assertion *the traversal reaches a point at which both intervals become empty simultaneously*. Hopefully these points will be the attractors of the information space as implied by matches:.

But how come the space looks like a collection of interval pairs and there is no mention of the pattern and the string? Now it seems they do not belong to the space at all. How is this possible?

> The behavior of matches: is configured by the pattern and the string. If we examine this situation carefully, we will see that at each point of the space of interval pairs, `matches:` makes a decision about where to go next based on the individual characters of the pattern and the string, and on the current position in the space. Oh. … so the pattern and the string specify a particular variety of traversal behavior. In other words, `matches:` translates the pattern and the string into a direction Vector at each step of the trip! > Or the direction in which mice traverse a Maze.

This suggests that in reality the static context is just the pair of intervals, that the space is one of interval pairs connected in the orientation specified by `aPattern matches: aString`, that we distinguish interesting accumulation points by drawing distinctions regarding the interval sizes, that we are able do so because we can perceive a difference between their possible values, and that the answer we are after is whether the particular traversal ends at an interesting accumulation point or not.

> You can also see `matches:` as discrete vector integration of a trajectory in the space of interval pairs.