Hacker News new | past | comments | ask | show | jobs | submit login
Fear and Loathing with APL (theburningmonk.com)
48 points by theburningmonk on June 12, 2015 | hide | past | favorite | 33 comments

"SQL, Lisp, and Haskell are the only programming languages that I've seen where one spends more time thinking than typing."

- Philip Greenspun

From http://www.paulgraham.com/quotes.html

I adore languages with a high thinking-to-googling ratio. I've been typing the code in this example. Even though I use my mouse to type APL characters, it feels fast. Really, really enjoyable.

Thanks to the author; this is readable and fun.

One of Iverson's changes when he created J as a successor to APL is that all the operators are ASCII characters.


Open source and even available on Android so it can be run on a phone.

A few years back, I ran into two professional APL developers. Apparently there are still 3 major commercial APL vendors (not counting IBM, which probably still sells APL2). Each targeting their own niche, and each being expensive if you're used to free compilers (starting on the order of $1k per seat).

A language that shares the same philosophy but is a little more approachable is J (jsoftware). Unlike APL, it only uses normal ascci punctuation marks. J is also open source, which is a big advantage over APL.

As for J's cousin K, the official K interpreters are commercial (with a free workspace-limited demo version for tinkering), but there is also an actively maintained open-source implementation called Kona: https://github.com/kevinlawler/kona

I think K is a bit more pleasant to read than J because it relies far less on digraphs, but naturally it's a matter of taste.

There's GNUapl which is coming along nicely.

Yup, GnuAPL is getting better every time I use it for anything. Dyalog for personal use is also very good and decently affordable (and they just released a Mac version, I got to test the beta as an interested user and it works very nicely)

APL is an awesome language with one glaring flaw. It's impossible to read and you need a special input method to type. I enjoy reading about it but I can't imagine I'd ever enjoy having to work with it.

That's two glaring flaws. You may want to try J, which only has one glaring flaw.

YMMV, but I find the readability of J and K to be far worse precisely because of the ASCII charset instead of the glyphs. The APL glyphs give me a concrete context switching mechanism that I'm operating within its "alphabet" and the semantics thereof. Whereas because I associate ASCII characters with plenty of other meanings already, I find J and K to look like complete line noise in comparison.

It seems like translating J or K to a glyph format for reading would be a relatively simple matter.

Would have to be a one to many relationship. Part of the problem with K is that the meaning of an operator depends on the type of the operands. "?" can be "generate a random number" or "search for an element in a list" for instance. And yes, that is insane.

Well, a parsing display system still sounds like a reasonably simple piece of software.

Still, while I met J author Roger Hui years ago in college, I've never run a line of J so I probably would be the one to create such a system.

Or numpy, which from what I can tell is basically a readable version of J. As a concrete example, I've gotten partway through translating the APL examples in "Notation as a Tool of Thought" (http://www.jsoftware.com/papers/tot.htm) into numpy, and they work pretty much unchanged.

If anyone knows APL/J/K well, and could show some programs where idiomatic APL/J/K does not directly translate into idiomatic numpy, I'd love to see them.

They have vectorization in common, but the commonalities really stop there.

Can you suggest a simple program for which idiomatic J differs significantly from idiomatic python/numpy? As I said, I've been unable to come up with one, or find one in aforementioned paper.

I cant speak for J but this is the first APL program I ever wrote (it's in Dyalog) it take a wolfram code on it's right and an array of 1s and 0s on the left and returns the next generation for that one dimensional automaton (it treats the world as wrapping but it would be easy to clamp the sides to 1 or 0):

  ODAT ← {(⊂[1] ¯1 0 1 ⌽ (3,⍴⍵)⍴⍵) ∊ ((8 ⍴ 2) ⊤ ⍺) / ⊂[1] 2 2 2 ⊤ ⌽ 0,⍳7 }
as a traditional function with comments and stuff its:


   ⍝ First construct the eight *P*ossible states:
   ⍝ Creates an array 7 6 5 4 3 2 1 0 (⌽0,⍳7) and converts to binary (2 2 2⊤)
   ⍝ 1 1 1 1 0 0 0 0
   ⍝ 1 1 0 0 1 1 0 0
   ⍝ 1 0 1 0 1 0 1 0
   ⍝ Then encloses along vertical axis (⊂[1])
   P←⊂[1]2 2 2⊤⌽0,⍳7

   ⍝ Convert the *R*ule from wolfram number to binary ((8⍴2)⊤R)
   ⍝ 110 becomes 0 1 1 0 1 1 1 0
   ⍝ Then choose *P*ropogating *S*tates (/P)

   ⍝ Take *S*tate and triplicates ((3,⍴S)⍴S) and rotates (¯1 0 1⌽) to create a matrix
   ⍝ each colume is a cell and it's *N*eighbors
   ⍝ A state 1 0 1 1 0 0 becomes:
   ⍝ 0 1 1 0 0 1
   ⍝ 1 0 1 1 0 0
   ⍝ 0 1 1 0 1 0
   ⍝ Then encloses vertically again
   N←⊂[1]¯1 0 1⌽(3,⍴S)⍴S

   ⍝ Now we have two arrays: 
   ⍝ *N* which is the current generation of state/neighbor triplets
   ⍝ *PS* which is the triplets that produce a live cell in the *N*ext *G*eneration.
   ⍝ we create a new array by testing for membership (∊) of current generation
   ⍝ and *P*ropogating *S*tates
   NG ← N∊PS
Some of that might be idiomatic python but the thing is I didn't write it as the multi-line function. I wrote it by modifying the one line function. Which I did because that's how APL's data-flowy syntax/semantics encourages you write things and doing that in one line sure as hell isn't idiomatic python.

The determined programmer can write any language in any language. It's what we write when we aren't being determined fortran/smalltalk/whatever programmers that speaks to the difference in programming languages.

Sure, this is how you compute Hofstader's Q sequence in J

Q=: 1:`(+&$:/@:- $:@-& 1 2)@.(>&2)"0 M.


If we are being precise then It's two symptoms of the same flaw.

Unicomp sells USA layout APL keycaps.


This is a Solitaire game in Dyalog APL, ostensibly: http://aplwiki.com/SolitaireGame

It's certainly esoteric, but I wouldn't say it's unreadable. Given that APL is like a programming alphabet of sorts, it'd be interesting to see how quickly and tersely one could put together infrastructure with it. Too bad it has virtually no ecosystem.

Readable, understandable even (with a lot of "I bet this symbol does this"), but not writable.

It may not be a meaningful comparison, but the commenting on the side is more reminiscent of assembly than a high-level language (i.e. the code itself is not sufficient to tell you what it's attempting to do). Is this how well-commented most APL turns out, or is this due to being a teaching piece of sorts?

Once you get accustomed to it, it's not really that hard to read. My problem is that I get unaccustomed to it really fast.

I haven't done any APL since college in the late 70's. We used Decwriters http://www.columbia.edu/cu/computinghistory/la36.html that had the special APL character set.

I have a secondary keyboard input method on my Mac for when I'm in APL mode. It just remaps my keyboard, and once I got used to it I know where most commands are (the basics, sure, some I have used less are harder to come by but I'm getting there slowly.) It's kind of learning vim or emacs: once you get the bindings you just forget about them and know by feel.

Non-standard character set aside; is the terseness (one-letter commands and such) partly because of the slow input devices at the time?

The terseness is because it was originally developed to be written on a blackboard while lecturing.

As CS developed in the math world Iverson realized that the existing math was crap for describing computational processes. So he made his own and as it turned out it, with a little modification it was executable.

I believe it's more likely to be partly related to the small console sizes that were typical at the time.

I don't think typing was slower then. And most programming time isn't spent typing.

I really hope "Fear and Loathing in/with $TOOL" doesn't become the new "How I learned to stop worrying and love $TOOL"

I hope "Johnny Depp’s Fear and Loathing in Las Vegas" is just one blogger's ignorance of American letters.

Fear and Loathing Considered Harmful?

I don't know why "x considered harmful" articles irk me so much, but they do

“Considered Harmful” Essays Considered Harmful


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact