Index   <<   >>

Take these two verbs — please

The innards of verbs to produce simple graphs or barcharts are much the same. Variations arise in whether to produce a graph or barchart, the orientations of the figures, the direction of numbering the vertical axis, and suchlike. Rather than produce a large number of separate verbs, one for each of these numerous possibilities, a better solution is to produce a plotting conjunction P that takes two verbs u and v as arguments, and produces a verb that, applied to a list of nonnegative integers, yields the desired result.

J provides facilities to make the job easier. Simply create a character string that gives the definition, using x for the left verb argument and y for the right verb argument, and apply the conjunction definition adverb 2 : .

   P=. 2 : 'x@(]y/>:@i.@(>./)){'' *''"_'
   u P v
u@(] v/ >:@i.@(>./)) { ' *'"_

   z=.2 9 7 4
   ((]P>: ; ]P=) ,: (|:P>: ; |.@|:P=)) z
┌─────────┬─────────┐
│**       │ *       │
│*********│        *│
│*******  │      *  │
│****     │   *     │
├─────────┼─────────┤
│****     │ *       │
│****     │         │
│ ***     │  *      │
│ ***     │         │
│ **      │         │
│ **      │   *     │
│ **      │         │
│ *       │*        │
│ *       │         │
└─────────┴─────────┘