Skip to content

How to Kill More Cats ...

Vector 7:1, page 115

programming techniques language design

Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 115

Peter Branson’s reply (Vector Vol.6 No.4) to my VCAT suggestions rightly takes me to task for using the pompous phrase ‘a modern didactic appraoach’. In simple terms I mean that APL2 allows us to cut through much of the algorithmic obscurity of old-time APL, thereby making APL2 of great value as a specification language. I agree with both Adrian and Peter that my VCAT is horrendously inefficient with screenful-sized matrices, but that I submit is not the point. Consider rather that VCAT is only the tip of an iceberg, in the sense that if you are motivated to have VCAT in your toolkit, you are likely also to want HCAT (horizontal catenation). Then there is the further matter of justification, - do you want primary (left/top) or secondary (right/bottom)? So generalise CAT to take a vector of matrices as right argument R and 1 or 2 as left argument to denote horizontal or vertical:

[0] Z←L CAT R
[1] Z←⊃[L]⊃,/⊂[L]¨R

      A B
WEE  RATHER
ONE  LARGER
     MATRIX


      (1 CAT A B)(2 CAT A B)
WEERATHER  WEE
ONELARGER  ONE
   MATRIX  RATHER
           LARGER
           MATRIX

Justification is then an exercise in using rotate as a dual transformation, and can be embodied in:

[0]  Z←L TAC R
[1]  Z←⌽[L]L CAT⌽[L]¨R

      (1 TAC A B)(2 TAC A B)
   RATHER       WEE
WEELARGER       ONE
ONEMATRIX    RATHER
             LARGER
             MATRIX

Now degeneracy has to be considered. A vector requiring catenation may be regarded either as a row or a column vector, so there is another 1/2 option for the left argument L of the function MAT which which converts its right argument R into a matrix.

[0]  Z←L MAT R
[1]  Z←⊃[L]1/⊂1/R

      (1 MAT 'PIG')(2 MAT 'PIG')
P  PIG
I
G

(1/R) on the right ensures that MAT will also deal with a scalar, but in order to work as a null function for a non-degenerate matrix R it is necessary to add the first line:

[.1]  →(2=⍴⍴R)/0

The eight significant choices, i.e. all combinations of horizontal/vertical, primary/secondary and row/column resolution have now been dealt with in a systematic way, leaving the path open for efficiency if the goal is other than a pure teaching one. I don’t think Peter and I have any fundamental disagreements, and I certainly don’t suggest the abandonment of old practices and idioms where these are of worth at the implementation stage. I do however advocate the use of APL2 at specification and design stages, and invite readers to pondor which the designer for efficiency has by viewing the whole of this particular problem so compactly.

Norman Thomson


Comment: I never though that such an innocuous little function could generate such interest; maybe we should expose some more ‘pragmatic antiques’ to competition from advanced APLs? Ed(ex).