I'm pretty sure there are about two people that can read and write that fluently: Roger Hui and Arthur Whitney.
"I did pure mathematics in school, but later I was a teaching assistant for a graduate course in computer algorithms. I could see that the professor was getting killed by the notation. He was trying to express the idea of different kinds of matrix inner products, saying if you have a directed graph and you're looking at connections, then you write this triple nested loop in Fortran or Algol. It took him an hour to express it. What he really wanted to show was that for a connected graph it was an or-dot-and. If it's a graph of pipe capacities, then maybe it's a plus-dot-min. If he'd had APL or K as a notation, he could have covered that in a few seconds or maybe a minute, but because of the notation he couldn't do it." - "A Conversation with Arthur Whitney" (http://queue.acm.org/detail.cfm?id=1531242)
A better way of doing this is Fortress, which tries to use mathematical notation when possible but doesn't try to compress it as small as possible.
#define DECLG V*sv=VAV(self);A gs=sv->g; \
AF g1=gs?VAV(gs)->f1:0,g2=gs?VAV(gs)->f2:0
Judging the quality of this code says nothing about the language and environment that this code provides. This is a very unusual style of C
"The unusual appearance is a side effect of writing C as concisely as possible. There are great benefits to writing code as concisely as possible. Someone familiar with the style can read and comprehend the code much faster than they would be able to with traditional code. It also creates a discipline that reduces bugs. Some of the benefits will not be apparent until you try it. Some of the downsides of the style are inaccessibility and a steep learning curve."You get used to code like that, and often, doing it that way makes sense. I first encountered it learning to read this short prototype interpreter (http://nsl.com/papers/origins.htm) by Arthur Whitney, which very strongly influenced the programming style in the J codebase.
As gruesom notes, this discussion has already happened numerous times in the HN archives. Your reaction is the APL equivalent of going, "OMG! Parens!!!!1!" when introduced to Lisp code.
I suspect part of the style comes from APLers typically being mathematicians as well as programmers, and drawing more from mathematics than typical "software engineering best practices" style.
Let's note that the payoff for departing from the mainstream in this way is not small: these languages achieve abstractive (compositional) power and elegance without sacrificing efficiency. Those two things are incompatible in nearly every other programming context -- so much so that it's a truism that higher-level code is shorter but slower, lower-level code is faster but more verbose. Yet here they happily co-exist.
But there is a key difference between the terseness and density of APL-derived languages and the C implementation of the runtime: in the actual languages, the semantics of the language are well defined and enforced by the compiler. C is a free-for-all. So while there is discipline behind the C code - and I can see that it mimics the language it implements - it must be self discipline. That makes it more dangerous, and objecting to that is not the same as objecting to the APL family of languages themselves.
(That one-page J interpreter is sometimes called the "J Incunabulum".)
See e.g. http://news.ycombinator.com/item?id=1458016 http://news.ycombinator.com/item?id=266982 http://news.ycombinator.com/item?id=697501 http://news.ycombinator.com/item?id=2176980
Any incentive I had to try this language is now gone and I want to erase the memory of its construction from my mind.
Code like this needs to be read more slowly than usual, because unlike much C code, the information level isn't low enough that you can read it lines at a time. Math papers have all these weird sigma symbols and stuff, too; you can't read just them as fast as you would read "for (i=0; i<N; i++) {" for the millionth time.
Likewise, rather than writing "for (i=0; i<N; i++) {" yet again, K just calls that ' and moves on. In the source, there's a macro called DO, which is used extensively. DO(N, Blk) -> for(i=0, int _n=N; i<_n; i++) { Blk } . The APLs are about having a notation that doesn't constantly get in the way of thinking about your actual problem.
It's funny that you bring up mathematical notation because mathematical notation is completely optimized for write-only. Mathematics is so obsessed with one letter variable names that they had to gather letters from other alphabets to continue their opaque tradition.
Mathematical "code" isn't usually meant to be read without the surrounding variable and notation declarations, for example "Let x be ..." or "where • is the ... operation". If those are provided, short variable names and terse notation allow for the intent to be presented clearly, without it being obscured by line-length restrictions and a limited number of generic constructs (eg. for-loops instead of the summation operator).
That said, I'm finding this C implementation of J to be pretty cryptic. Of course, that's no reason to dismiss the J programming language itself.
% jconsole
|file name error
| 0!:0 y
load 'packages/misc/fndisplay.ijs'
|value error: load
| load'packages/misc/fndisplay.ijs'
(I tried with absolute paths too)Any idea what I might be missing? And do you know the license of the libraries?
Some of us are trying to organize our efforts here: https://github.com/openj/core
We don't intend on mucking with the code much at this point, just patching together a better build system, etc.