Fifty Shades of J/Chapter 03

From J Wiki
Jump to navigation Jump to search

Table of Contents ... Glossary ... Previous Chapter ... Next Chapter

My J-oinery Workshop

Principal Topics

, (ravel/append) ,.(ravel item , stitch) ,: (laminate) -. (less), ” (rank conjunction), autostereograms

Joinery

It is a happy accident that ‘join’ is not the name of a primitive verb in J because this makes it appropriate to use the word as a generic name for the three primitive verbs append, stitch and laminate. Some analogies with what goes on in the wood-yard seem appropriate.

Suppose I have a pile of planks and I want to stack a second pile on top. My appender (,) takes good care of me so that I do not have to worry about imbalance due to non-matching widths, although it does keep appropriate space clear in order to keep everything in tidy overall order.

   ]App=.(2 3$'abc'),(3 4$'defg')
abc
abc
defg
defg
defg

Next I use my stitcher (,.) when I want to stack two planks side by side, and then join plank to plank in matching pairs. Naturally the stitcher only works when the number of planks in the two piles are equal.

   ]St=.(2 3$'abc'),.(2 4$'defg')
abcdefg
abcdefg

Next my laminator (,:) starts a new pile from two existing piles. Like the appender I do not have to worry about imbalance due to non-matching widths.

   ]Lam=.(2 3$'abc'),:(3 4$'defg')
abc
abc


defg
defg
defg

The shaper ($) starts its work as a laminator and continues as an appender. In this sense the laminator is one of the lowest level (most primitive) operators in the overall J tool kit, and thus one of the most pervasive verbs even although its explicit usage is relatively small.

Another valuable little tool is my gouge (-.) which helps me dig out unwanted bits like knots

   'abcdef'-.'bd'
acef

When it comes to finding and rearranging things in the workshop, I reach for one of what I call my monadics. First the raveller (,) which lays everything out in a line, using my gouge to close up the spaces which may have been put in for overall tidiness :

   Ravel=.-.&' '@,
   (Ravel App);(Ravel St);(Ravel Lam)
┌──────────────────┬──────────────┬──────────────────┐
│abcabcdefgdefgdefg│abcdefgabcdefg│abcabcdefgdefgdefg│
└──────────────────┴──────────────┴──────────────────┘

Next my spacesaver tool which I affectionately call my ‘ri’ (short for Ravel Items). This comes into play in two circumstances, one when I want to stack a plank vertically instead of horizontally

   ,.'abcd'
a
b
c
d

and the other when I want to put my two laminated stacks one on top of the other which I can do in either of two ways

   (,.Lam);(,/Lam)
┌────────────┬────┐
│abc abc     │abc │
│defgdefgdefg│abc │
│            │    │
│            │defg│
│            │defg│
│            │defg│
└────────────┴────┘

each of which has the effect of reducing the number of piles (rank in J terminology).

   ($Lam);($,.Lam);($,/Lam)
┌─────┬────┬───┐
│2 3 4│2 12│6 4│
└─────┴────┴───┘

My accountant tells me that ,. (ravel items) is also very handy for making lists into columns (easier to total up, I suppose)

   ,.i.5
0
1
2
3
4

To complete the picture, my itemizer puts a band around all of my timber arrangements. You won’t see any visible difference but the shaper shows it clearly :

   ($App);($St);($Lam)
┌───┬───┬─────┐
│5 4│2 7│2 3 4│
└───┴───┴─────┘
   ($,:App);($,:St);($,:Lam)
┌─────┬─────┬───────┐
│1 5 4│1 2 7│1 2 3 4│
└─────┴─────┴───────┘

What I haven’t told you about is my packing machine known as the ‘boxer’ which opens up many possibilities for joining at the package level which will be exploited elsewhere.

   <"1 App
┌────┬────┬────┬────┬────┐
│abc │abc │defg│defg│defg│
└────┴────┴────┴────┴────┘
   <"1 St
┌───────┬───────┐
│abcdefg│abcdefg│
└───────┴───────┘
   <"1 Lam
┌────┬────┬────┐
│abc │abc │    │
├────┼────┼────┤
│defg│defg│defg│
└────┴────┴────┘
   <"2 Lam
┌────┬────┐
│abc │defg│
│abc │defg│
│    │defg│
└────┴────┘

The last step is a demonstration of the tools in use. The editor was not sympathetic to my idea of distributing a set of planks with Vector, so I have to fall back on a diagram from the book “How the Mind Works” by the American psychologist Stephen Pinker. He uses this diagram to explain how autostereograms are constructed. The basis of the diagram is that in the short lines two 4s have been removed; in the long lines two Xs have been inserted between 3 and 4. The diagram is itself an autostereogram - look at these two areas and use stereogram viewing techniques and you should see a raised and a recessed rectangular block respectively.

123456789012345678901234567890123456789012345678901234567890  
123456789012345678901234567890123456789012345678901234567890  
123456789012345678901234567890123456789012345678901234567890  
1234567890123456789012356789012356789012345678901234567890    
1234567890123456789012356789012356789012345678901234567890    
1234567890123456789012356789012356789012345678901234567890    
1234567890123456789012356789012356789012345678901234567890    
1234567890123456789012356789012356789012345678901234567890    
1234567890123456789012356789012356789012345678901234567890    
123456789012345678901234567890123456789012345678901234567890  
123456789012345678901234567890123456789012345678901234567890  
123456789012345678901234567890123456789012345678901234567890  
12345678901234567890123X4567890123X456789012345678901234567890
12345678901234567890123X4567890123X456789012345678901234567890
12345678901234567890123X4567890123X456789012345678901234567890
12345678901234567890123X4567890123X456789012345678901234567890
12345678901234567890123X4567890123X456789012345678901234567890
12345678901234567890123X4567890123X456789012345678901234567890
123456789012345678901234567890123456789012345678901234567890  
123456789012345678901234567890123456789012345678901234567890  
123456789012345678901234567890123456789012345678901234567890

A blueprint for the diagram is:

Fsoj3a.png

Here is how the appender, stitcher and gouge realise this blueprint

   t=.'123X4567890'
   u=.t-.'X'
   v=.u-.'4'
   a=.21 20$u
   b=.3 40$u
   c=.(6 18$v),.6 20$u
   d=.(6 22$t),.6 20$u
   a,.b,c,b,d,b

Another possibility is to use ,.

   A=.3 60$u
   B=.(6 20$u),.(6 18$v),.6 20$u
   C=.(6 20$u),.(6 22$t),.6 20$u

The Pinker diagram is then obtained by

   A , B , A , C , A

Ah well, time to close up the workshop for another day.

Code Summary

Script

File:Fsojc03.ijs