News for hackers. Stuff that matters.
Re:What can you do in 2k LOC of C? by EliRivers on Friday February 04, 2011 @05:12AM (#2178965)
"That's interesting, but damn is that some ugly code"

I would disagree. That code is beautiful. Elegance and brevity; it's as close to a pure expression of the coder's thoughts as it's reasonably possible to get.

Re:What can you do in 2k LOC of C? by silversmith on Friday February 04, 2011 @08:53AM (#2179372)
Excuse me, but in my programming thought flow, there are checksums and limits, not c's and l's, and my code reflects that. Do I not qualify as a coder?
Re:What can you do in 2k LOC of C? by silentbicycle on Friday February 04, 2011 @09:47AM (#2179553)
Quick, what does the i stand for in "for (i=0; i<n; i++) {"?

It was a quick prototype written by one APLer, for another APLer, using mutually understood conventions. For example, its dyadic verbs ("V2" functions) use the variable names 'a' and 'w'. For a while, I wondered why (maybe they stood for "Arthur" and "Whitney"?), but after reading Iverson's _A Programming Language_, I realized APL usually uses lowercase alpha (α) and omega (ω), which look like 'a' and 'w' in ASCII. Details like that would need no explanation.

Likewise, in

    typedef struct a{I t,r,d[3],p[2];}*A;
t is type (is it boxed? 0 or 1), r is rank (number of dimensions), d is the dimensions (hardcoded to a max of 3; a 2x3x4 matrix has d={2,3,4}), and p is a variable-length array sized by malloc-ing extra space; that's where the values go, either longs or void pointers). That'll save you some time if you ever try to pick the rest apart. :)

APL code is often terse to the point of seeming cryptic, just math papers are. You get used to it, and it's that way for a reason.

Re:What can you do in 2k LOC of C? by ehsanul on Friday February 04, 2011 @11:10AM (#2179899)
Wow, thanks for that clue. Will have to take a closer look at that source now. I don't feel too bad for not really getting it, given the creator of J saying this about it:

My immediate reaction on seeing the page was recoil and puzzlement: it looked nothing like any C code I had ever seen. (“Is it even C?”) However, Ken counselled that I should reserve judgment. As recounted in An Implementation of J, it then happened that:

I studied this interpreter for about a week for its organization and programming style; and on Sunday, August 27, 1989, at about four o’clock in the afternoon, wrote the first line of code that became the implementation described in this document.

The name “J” was chosen a few minutes later, when it became necessary to save the interpreter source file for the first time.

Re:What can you do in 2k LOC of C? by silentbicycle on Friday February 04, 2011 @11:19AM (#2179940)
If it intrigues you, check out Henry Rich's _J for C Programmers_. There's a free PDF on Lulu, and it's included with J (http://www.jsoftware.com/).

Like Emacs, J's internal documentation is excellent, but you have to learn its idiosyncratic terminology before you can actually find things.

Re:What can you do in 2k LOC of C? by sofuture on Friday February 04, 2011 @09:35AM (#2179510)
I obviously can't speak to Arthur Whitney's state of mind circa some summer afternoon 1990, but I don't believe the code is an attempt to obfuscate or be snobby/elitist at all. He was simply trying to express the basics of an idea in a terse form. It's the APL way.

I, for one, am happy simply finding the code 'of interest'. It's not great code, it's the initial sketch of an idea (I'll bet you AW would admit that readily (plus Roger Hui refers to it as "Incunabulum", which seems a bit tongue in cheek)) -- but, it's certainly not something you see every day, and it is thought provoking.