According to Aaron Hsu, the starting point for APL programming is the relational model.
I’m mixed on this, because I don’t think J has a natural concept of table, actually. Moreover, it seems like your code gets littered with head {. and constant-powered { lookups if you do represent data in a tabular format, with heterogeneous rows. I could be wrong, but it seems to work better in general when you have homogeneous arrays. Creating weird packets of data like we do in other languages just doesn’t seem to be the ticket here.
Suppose you design a table like this:
You will probably wind up using 0 { or 1 { to take it apart to do different things with the different columns. So I would probably build this table in J like so:
developers =. 'alice'; 'bob'; 'calvin'; 'delilah'; 'ellen' devemails =. '[email protected]'; '[email protected]'; '[email protected]'; '[email protected]'; '[email protected]'This is maybe a column-oriented view of the world. You can recover the table pretty easily though:
developers ,. devemails ┌───────┬─────────────┐ │alice │[email protected]│ ├───────┼─────────────┤ │bob │[email protected]│ ├───────┼─────────────┤ │calvin │[email protected]│ ├───────┼─────────────┤ │delilah│[email protected]│ ├───────┼─────────────┤ │ellen │[email protected]│ └───────┴─────────────┘Projection is sort of obvious now, you have to choose the columns you want because you don’t have the table, as it were. Selection isn’t so bad; you are going to filter on a certain column and apply that filter on the other column. Let’s find the developers with an “a” in their name:
developers #~ 'a' e."1> developers ┌─────┬──────┬───────┐ │alice│calvin│delilah│ └─────┴──────┴───────┘The same selection works on the other column, and you can still stitch together columns to make a table:
devemails #~ 'a' e."1> developers ┌─────────────┬─────────────┬─────────────┐ │[email protected]│[email protected]│[email protected]│ └─────────────┴─────────────┴─────────────┘ (#&developers ,. #&devemails) 'a' e."1> developers ┌───────┬─────────────┐ │alice │[email protected]│ ├───────┼─────────────┤ │calvin │[email protected]│ ├───────┼─────────────┤ │delilah│[email protected]│ └───────┴─────────────┘Joins work by doing lookups by index. Let’s introduce another table:
| alphago | calvin |
| bitbucket | ellen |
| cafeteria | delilah |
| diffie | alice |
| entryway | bob |
| finality | alice |
| grace | delilah |
| homelab | calvin |
Following the earlier example we get this:
projects =. 'alphago'; 'bitbucket'; 'cafeteria'; 'diffie'; 'entryway'; 'finality'; 'grace'; 'homelab' projdevs =. 'calvin'; 'ellen'; 'delilah'; 'alice'; 'bob'; 'alice'; 'delilah'; 'calvin' projects ,. projdevs ┌─────────┬───────┐ │alphago │calvin │ ├─────────┼───────┤ │bitbucket│ellen │ ├─────────┼───────┤ │cafeteria│delilah│ ├─────────┼───────┤ │diffie │alice │ ├─────────┼───────┤ │entryway │bob │ ├─────────┼───────┤ │finality │alice │ ├─────────┼───────┤ │grace │delilah│ ├─────────┼───────┤ │homelab │calvin │ └─────────┴───────┘We can find the email of the developer for each project like so:
(developers i. projdevs) { devemails ┌─────────────┬─────────────┬─────────────┬─────────────┬─────────────┬─────────────┬─────────────┬─────────────┐ │[email protected]│[email protected]│[email protected]│[email protected]│[email protected]│[email protected]│[email protected]│[email protected]│ └─────────────┴─────────────┴─────────────┴─────────────┴─────────────┴─────────────┴─────────────┴─────────────┘This might be easier to read as a table, so let’s do that:
projects ,. projdevs ,. devemails {~ developers i. projdevs ┌─────────┬───────┬─────────────┐ │alphago │calvin │[email protected]│ ├─────────┼───────┼─────────────┤ │bitbucket│ellen │[email protected]│ ├─────────┼───────┼─────────────┤ │cafeteria│delilah│[email protected]│ ├─────────┼───────┼─────────────┤ │diffie │alice │[email protected]│ ├─────────┼───────┼─────────────┤ │entryway │bob │[email protected]│ ├─────────┼───────┼─────────────┤ │finality │alice │[email protected]│ ├─────────┼───────┼─────────────┤ │grace │delilah│[email protected]│ ├─────────┼───────┼─────────────┤ │homelab │calvin │[email protected]│ └─────────┴───────┴─────────────┘So there’s some basic relational-type stuff in J. Is this the right approach? I don’t know.
.png)

