We'll now look at how we might have developed the "distance between point pairs" code using Dissect to see how this tool parallels what we did "by hand" originally.
Going back to the beginning ("Variations on a Theme") where we were attempting to apply +/ to the square of the differences, then apply the inverse of square (square root or %:) using "under" like this:
0 0 ([: +/&.*: -) 1 1 1 1
Dissecting this expression
ds '0 0 ([: +/&.*: -) 1 1'
gives us this result when we dissect it:
So we see where we go wrong - at the summation +/ of the square of the differences - much as we saw with our simple debugging technique of manually applying an increasing number of operations.
The attempt that gave us a syntax error originally does something else when we try to dissect it:
ds '0 0 ([: +/(&."_)*: -) 1 1' attention interrupt |attention interrupt: failparse | 13!:8(1)
Apparently dissect won't attempt to parse something so obviously syntactically incorrect.
Moving on to our next attempt that gives us two results when we were expecting three:
([:%:[:+/[:*:[:-/]) pts 2.44949 2.44949
Dissecting this highlights the problem area: the summation across the incorrect axis again.
Applying the fix by specifying the correct rank for summation gives us a better result:
Now let's look at the more elegant version we found in the J phrase-book:
NB.*dPP v distance between 2 points dPP=: [: +/&.:*: - dPP/0 0 ,: 1 1 1.41421
The dissection shows us what we have come to expect:
However, the explanation for our final sentence - the modified version of the one from the phrase book using the infinite-rank version of "under" (&.:) - isn't very illuminating.
Perhaps the tool does not yet handle this variant adverb.
Some experimentation shows us that using the phrase dyadically gives a more illuminating dissection: