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