4 ms·
Shocked that silentbicycle hasn't mentioned it already, but Arthur Whitney whipped up the first prototype/inspiration for the J language in a short bit of macro
by sofuture 16y ago
Shocked that silentbicycle hasn't mentioned it already, but Arthur Whitney whipped up the first prototype/inspiration for the J language in a short bit of macro heavy C over the course of an afternoon.
42 lines?
http://pastebin.com/s2usuqDq http://pastebin.com/s2usuqDq
If this interests you at all, absolutely worth reading Roger Hui's retrospective on the subject (more about J + Ken Iverson, but definitely fascinating) http://keiapl.org/rhui/ http://keiapl.org/rhui/
- ehsanul 16y agoThat's interesting, but damn is that some ugly code. Slightly obfuscated on purpose? Though of course it wouldn't win the IOCCC. On the other hand, it's notable that many IOCCC submissions happen to pack a lot of functionality in often less than 2k. I remember reading a few descriptions of some the winning entries, but I can't find that now. Here's a glimpse though: http://cboard.cprogramming.com/brief-history-cprogramming-com/123-ioccc.html http://cboard.cprogramming.com/brief-history-cprogramming-co...
- ehsanul 16y agoNevermind the comment about it being slightly obfuscated. Have to realize that this is the creator of J we're talking about. He probably saw it as highly expressive code (much meaning in as few characters as possible). Though I can't agree, it is definitely amazing that something so small could be the start of something like J.
- silentbicycle 16y agoIt was actually written by Arthur Whitney, the author of K (not J), though Roger Hui (of J) studied it beforehand. I do recommend studying it, though. Their APL dialects are really something; I wish there were good fully open-source implementations, and writing one is on my queue. Kona (http://github.com/kevinlawler/kona http://github.com/kevinlawler/kona), an open-source implementation of K 3.2, is also coming along. Just be warned that APLer C is usually nasty, brutish, and short. :) FWIW, the best thing I've seen for getting the J mindset is _J for C Programmers_ - as Henry Rich says, to do J you must "think big" - don't think "for each part of this list, do this, then this, then this...", think, "apply this operation over these.". That scales up to multiple dimensions, and can often be run in parallel. :)
- silentbicycle 16y agoHaving spent a lot of time meditating on it (as sofuture mentioned), it isn't "slightly obfuscated" so much as "stubbornly written like APL rather than C". If you become inexplicably fascinated by that code and want help unraveling it, my contact info is in my profile. I don't consider it noteworthy as a useful program under 2kloc (on modern hardware it usually just crashes, it's quite cavalier with pointer casting, and clearly a quick prototype either way), but it's like a pink space laser beam of insight about the APL mindset. Real APLs take more than a page, but not that much more. Eliding loops does that. A lot of the IOCCC code is also delightfully perverse, too. Highly recommended.
- ehsanul 16y agoYeah, I realized that fact a little late. Relevant snippet from the link about that initial bit of code for J: I showed this fragment to others in the hope of interesting someone competent in both C and APL to take up the work, and soon recruited Roger Hui, who was attracted in part by the unusual style of C programming used by Arthur, a style that made heavy use of preprocessing facilities to permit writing further C in a distinctly APL style.
- silentbicycle 16y agoArthur's C is stubbornly unconventional, but often, he's got a point. Also, the APL community seems to be pretty disjoint from the rest of CS (though Arthur is also a Lisper). I think it'd be mutually beneficial if the APLers and the MLers got together, in particular.
- EliRivers 16y ago"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.
- silversmith 16y agoExcuse 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?
- sofuture 16y agoI 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.
- silentbicycle 16y agoQuick, 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.
- jpr 16y ago> http://pastebin.com/s2usuqDq http://pastebin.com/s2usuqDq I'm going to save this for the next time someone asks why there aren't more females in CS/programming. I just tell them that this kind of code is held in high esteem, instead of being ridiculed for the stupidity that it is.
- aisi 16y agoAnd how is that at all related to female numbers in CS/programming?
- EliRivers 16y agoAre you saying that women can't appreciate elegance and brevity? Perhaps your kind of attitude is why there aren't more females in programming.
- jpr 16y agoOr perhaps it's people who mistake obfuscation for elegance and brevity.
- sofuture 16y agoI'd love to hear why that code doesn't embody brevity? As for obfuscation, it's rather straightforward -- it's just concise. A lack of instant understanding doesn't indicate that a piece of code is without merit, or not honest and straightforward.
- kenjackson 16y agoTo be clear. If someone submitted this code to you for code review you'd say, "nice and concise -- approved"? Really? I get this person may have been working with constraints we don't know about, but its not straightforward. Give this to 10 working C devs and ask them to tell you what it does without running it. The standard cues of straightforward code aren't there -- well named variables, well named functions, comments, indentation, etc...
- ehsanul 16y agoOn a related note, reading J's getting started guide has been pretty interesting so far: http://www.jsoftware.com/help/primer/contents.htm http://www.jsoftware.com/help/primer/contents.htm