I've been reading through the following old papers, written by a fellow named Bruce MacLennan during the 1980's:
- Introduction to Relational Programming (Jun 1981) https://archive.org/details/introductiontore00macl - Overview of relational programming (Nov 1981) https://archive.org/details/overviewofrelati00macl - A Relational Program for a Syntax Directed Editor (Apr 1982) https://archive.org/details/relationalprogra00macl - Relational Programming (Sep 1983) https://archive.org/details/relationalprogra83012macl - Four Relational Programs (Nov 1986) https://archive.org/details/fourrelationalpr00macl Like J, this guy's work appears to have been influenced by both APL and FP (the language proposed by John Backus in his "Can programming be Liberated from the Von Neumann Style?" talk). Also like J, the code tends to be quite terse and expressive. For example, the syntax directed editor just over 2 pages of typewritten code. I've been working on porting the syntax directed editor over to J here: https://github.com/tangentstorm/drastic/blob/syndir/syndir.ijs I've also got a handful of relational words defined here: https://github.com/tangentstorm/tangentlabs/blob/master/j/rel.ijs MacLennan's work deals with binary relations, where a relation is something like a verb/function that may produce more than one result for a given input, and whose inverse is also a relation. For example, whereas (*:) represents the "square function" in J, (*: :. (+,-)@%:) might represent the "square relation". In addition, a binary relation can be defined by creating an array of shape (n, 2). MacLennan's language is untyped, but allows restricting either side of a relation by a predicate (which is just a relation mapping objects to boolean values), so a relational array might actually contain any number of boxed columns. In my code, I've started to implement relations as objects, thinking I could use them as a common interface for both the formulaic and tabular varieties. I've also created some words that allow you to define relations as a normal table of values (like you might find in a relational database), plus an index at which to "split" the table vertically so it can function as a mapping. For example: doubles =: (,. +:) i:5 NB. dyadic relation y=2*x, restricted to i:5 squares =: (,. *:) i:5 NB. dyadic relation y=x^2, restricted to i:5 monad ar [a]pplies a (tabular) [r]elation to an input: squares ar 4 16 The converse of a tabular relation is just: cv =: ( |."_1 ) : ( -@[ |."1 ] ) NB. dydadic case is for n columns + split monad ac [a]pplies the [c]onverse of a tabular relation. squares ac 4 _2 2 Now we can join the two tables on column 0 from each: squares 0 0 J doubles _5 25 _10 _4 16 _8 _3 9 _6 _2 4 _4 _1 1 _2 0 0 0 1 1 2 2 4 4 3 9 6 4 16 8 5 25 10 Applying the converse of this result is something like solving the following algebra problem: NB. Solve for x, given ( 25 = x ^ 2 ) and ( _10 = 2 * x ). 2 (squares 0 0 J doubles) ac 25 _10 _5 Anyway, this is all in the very early stages but I thought maybe someone else would find it interesting. The code is all open source under a permissive license if anyone's interested in collaborating. (It's also what prompted me to look into JDB.) ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
