Dan wrote: >My contention (and I think Ian and Henry's, though I don't want to put >words in their mouths) is that J encourages holistic (i.e. all-at-once) >thinking, which makes the use of } much rarer in J than one would expect >coming from other languages.
Yes, I'd go along with that. Splitting hairs, I'd not say "J encourages holistic [programming]" so much as being designed to perform it efficiently. One motivation for NuVoc was that the way J currently presents itself to a newcomer does not actually "encourage" said newcomer to use it in its most efficient way -- and Amend is one of the worst shapeshifters in that regard. Thus, in certain strictly limited circumstances, Amend will actually do in-place updating -- it will change portions of a noun in place (that is, without making a new copy of the noun). For details, see: http://www.jsoftware.com/jwiki/Vocabulary/curlyrt -under the headings "More Information" and (both valencies) "Use These Combinations". Might I just say in passing that Henry has done a splendid job of documenting "special combinations" (SCs) of primitives which J recognises and implements in a far more efficient way than the primitives themselves lead you to expect. These SCs are exhaustively laid bare in: http://www.jsoftware.com/jwiki/Vocabulary/SpecialCombinations and the relevant bits of this page are broken out and inserted into each primitive-page under the heading "Use These Combinations". As a bonus, these SCs are a good source of neat solutions to common tasks - which of course is not unconnected to their being chosen for fast-tracking. Amend is one of the primitives to benefit in this way. I confess I had no inkling of this before I collaborated with Henry on re-documenting Amend. Had I done so, I might have viewed Amend more favorably when I first encountered it. In my defence I'd like to say I'd just come off an innovative OLAP project written in APL, which rested heavily on flipping individual bits inside vast multidimensional Boolean arrays, and doing it as fast as possible. The idea that J would make a copy of the whole array just to flip one d*** bit struck me as egregious. On Wed, Jul 9, 2014 at 12:43 AM, Dan Bron <[email protected]> wrote: > Dan wrote: > > I rarely find a call for } . I'm wondering if you've > > [Pepe] have invented or discovered generally beneficial > > uses of } unrelated to performance. > > Pascal responded: > > I think } (dyadic amend) is pretty essential. > > The obvious use is amending one (or sublist) item > > from a data structure. > > Dan: > > Do you have examples, in practice, where you've wanted to > > modify one item (or a sublist) from a data structure? > > Pascal: > > A database. A moderate to large application is likely > > to track a data structure that needs item/row updates. > > Since we're discussing how J differs from other languages, and how that > affects the way we approach problems and express solutions, I'd prefer to > keep this concrete, using demonstrable examples from personal experience. > > Put another way, it's not difficult to come up with potential uses for }, > but that begs the question we're trying to answer: do *think* we'll need } > a lot because other languages have trained us to think that way? Or do we > actually *use* } a lot, because it's the best way to solve the problem at > hand? > > My contention (and I think Ian and Henry's, though I don't want to put > words in their mouths) is that J encourages holistic (i.e. all-at-once) > thinking, which makes the use of } much rarer in J than one would expect > coming from other languages. And that furthermore the circumstances under > which one might expect to use }, we end up approaching in a completely > different way in J, because J is a very different kind of language [1]. > > So my expectation is that if we actually look at how J is used, in the > wild, we'll see much smaller proportion of } than we'd otherwise expect > (excluding early contributions from language newcomers who will of course > start out by writing J programs in a very C-like [or Java-like, or > whatever] way). > > Raul wrote: > > In about 18k of code, I'm just shy of a dozen uses of } > > That feels about right, to me. > > I did a little analysis of my own on the codebase shipped with J (that is, > the standard library and all the Addons), and came up with the following: > > Number of files processed: 1,041 > Total lines: 196,590 > Total words: 954,264 > Total primitive words: 335,703 > ------ > Amend (}) appears 1586 times, giving it rank #36 out of 116 > primitives. > Amend represents about about 1 out of every 211 primitive words, > and 1/601 (0.17%) of all words. > ------ > Closest neighbors: > PRIM RANK COUNT PFREQ WFREQ WPCT > ---- ---- ----- ----- ----- ----- > <. 34 1,625 207 587 0.17% > {: 35 1,592 211 599 0.17% > ==> } 36 1,586 212 602 0.17% <== > _ 37 1,483 226 643 0.16% > {:: 38 1,441 233 662 0.15% > > Which shows } somewhat more prevalent than I expected, but it would still > be hard to call it popular (it ranks just above {::, for example). > Digging deeper, if you look at the histogram of primitive frequencies, > you'd note a pareto-like distribution, with the top 20 primitives > accounting for ~30% of use, and the remaining 100 or so primitives sharing > the balance, distributed over a long, shallow tail. This pattern persists > even if we restrict our attention to adverbs, though in that cohort } is > closer to "popular", and, (surprisingly!) \. is nearly forgotten [2]. > > So the takeaway is, among code written by both J Software itself and the > luminaries of the community (i.e. Addon authors), amend is neither > particularly common nor especially rare. That's compared to other > middling J primitives, of course; compared to how often amendment is used > in "mainstream" languages, } is a freaking unicorn. > > -Dan > > [1] I'm told that in Japanese, it's impossible to talk to someone without > implicitly describing your social relation to that person, because all > forms of address have social hierarchy baked into them. > > That is, you can't say "Hello"; you can only say "Hello, person who stands > slightly above me in the social hierarchy", or "Hello, person who is my > close friend", or "Hello, person who is the Emperor of Japan". If that's > true, then imagine the difference between the expectation and reality of a > native Japanese speaker who moved to Cuba, where everyone - including the > supreme leader - is addressed as "comrade" ("friend and equal"). Things > are just done differently in the two languages. > > Similarly, I believe the Piraha language forces one to declare how one > knows a piece of information. For example, you can't just report to > someone that "Mary caught a fish"; the grammar doesn't support that. > Instead, you would say "I (personally) saw Mary catch a fish" (firsthand > knowledge), or "John told me he saw Mary caught a fish" (hearsay), and so > forth. Imagine a Piraha person coming to NYC (or wherever) and learning > that in English one has no way to determine the source of a given piece of > information - how does one know it is reliable? > > [2] Actually, this observation (/. unloved?) makes me wonder whether > analysis is flawed; if you want to play with it yourself, you can get the > code from my SVN repo. No warranty express or implied, batteries not > included, etc: > > > http://www.jsoftware.com/svn/DanBron/trunk/environment/amend_frequency.ijs > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
