Monadic hook (f g) y is a generalization of reflexive. In fact, (f ]) y ≡ f~ y . In general, hook reflects its argument with a modified self on the right. For example, (>. -) is magnitude, (% >./) is scaling. -- OlegKobchenko 2006-05-22
This page is meant to focus on the reflexive. It is true that hook is a generalization of reflexive, but why stop there? Fork is a generalization of hook, and the monad f~ is just the monad of the fork ] f ] . -- RogerHui 2006-05-22 16:33:19
Discussing a subject, it is good to mention related areas. There is an immediate analogy: y f y and y f g y . And the idea about fork is good too: (h y) f (g y). The common benefit of these facilities is reusing the argument without explicit indication, thus extending the possibilities for tacit expressions. -- OlegKobchenko 2006-05-22 17:39:52
In this case, by mentioning too many things you lose focus and can lead the reader astray. See following item. -- RogerHui 2006-05-22 19:43:37
... or the writer, yes. I suggest moving the proceedings of this discussion into a new topic, such as "Tacitization", then link from here. It would describe the role of each feature (reflexive, passive, hook, fork, atop, etc.) with patterns (use cases) and examples, etc. -- OlegKobchenko 2006-05-22 20:48:42
Perhaps we should mention the contexts where a person learning, reading, or maintaining J code is likely to encounter ~. I find it is usually applied as a stylistic measure. Apropos of the preceding comments, it is usually in association with either hook or fork:
One of the most common and useful applications of ~ is within a hook. Two examples:
Monadic filtering: #~ f where f is the filter, e.g. #~ 0 < ] NB. Select positive numbers
Classification of data: g/.~ f where f is the classification function and g processes classes, e.g. </.~ * NB. Group by sign
Another common use of ~ is in forks. To increase readability, ~ is used to shorten or simplify long trains. That is: a complex, parenthesized right tine (usually a train itself) is often swapped with a simpler left tine, with the middle tine commuted, so that the parens around the tine can be removed. Example:
(+/ % #) % <./ becomes <./ %~ +/ % #.
This transformation is usually applied both iteratively and recursively, resulting in a flattened (minimally parenthesized), but equivalent train. I call this transformation flattening, front-loading, or right-loading.
-- DanBron 2006-05-22 18:08:14
The use of ~ in the preceding point is irrelevant, as in both cases it is the dyad f~ (passive or commute) that is used. -- RogerHui 2006-05-22 19:43:37
I was aware, when I wrote them, that my comments made no use of "reflexive". Notice that I don't use that word, but I do use the word "commuted" (and "swapped"). Most references are to the symbol ~ (hence "... is likely to encounter ~") . I wasn't led astray so much as I was continuing a train of thought (hence "Apropos of the preceding comments ... "). Oleg has given a useful name to the ideas I was trying to express.
I think such a essay would be more useful and interesting than one dedicated only to "reflexive", as dyadic invocations of f~ are much more common, widespread, and useful than monadic invocations. Of the examples given, I, personally, have only ever used 2. Of the remainder, half are reproductions of primitives.
-- DanBron 2006-05-22 21:19:04
Well then you should write that other essay, rather than try to cram unrelated ideas into an essay on reflexive. -- RogerHui 2006-05-22 21:28:07
The discussion will continue here. The material of the discussion will be gradually adapted for the body of this topic. -- OlegKobchenko 2006-05-22 23:22:51
I had only the idea to help users read code. I did not have the idea to split it onto a seperate essay. The credit there belongs to Oleg. I considered my comments incentives to rename and repurpose your essay. Moot now; we have the skeleton of the new essay. -- DanBron 2006-05-23 00:28:36