Live data from Hacker News

A deep dive into APL

curtisautery.appspot.com

21–30 of 93 posts

Re: A deep dive into APL

#21
I've slowly been going through "J Tutorial and Statistical Package", which teaches J (Iverson's evolution of APL which uses only ASCII characters) in the context of building a library for statistics[1]. I've found that it's a great way to learn the language, and that stats is a domain where APL languages work very well. I also read an interesting paper about using APL to create a notation for statistics, such as "normal prob between 0 2"[2]. Another nice thing about J is that it's GPL'd and free to use commercially.

[1] https://webdocs.cs.ualberta.ca/~smillie/Jpage/jtsp.pdf

[2] http://archive.vector.org.uk/art10501700

Re: A deep dive into APL

#22
post #7
post #4

Is APL still used for anything now? It seems like it could be a useful language for _something_.

I tend to think about APL as an alternative to R. When working with array-based datasets it's a very nice tool to use. APL has a small number of very flexible operations, and the key to using APL efficiently lies in understanding these primitives to achieve your goal. Once you learn them, it's more comfortable to use than learning all the intricacies of the R language. I wouldn't recommend anyone writing a full appli…

Hmm, I don't know APL or R, but I suspect I could have substituted "Numerical Python" for "MATLAB" for "R" in your post and have left the meaning almost unchanged.

Is my suspicion correct?

BTW: A mere 20 lines for format conversion is very good. Although by APL standards, it might be terrible.

Re: A deep dive into APL

#23

I am blown away to see how frequently APL seems to come up on HN these days, a language I used professionally for over ten years. As much as I love it I have to say one of the issues with APL is that it was way ahead of it's time. Because of that it struggled to run on computers of that era. I was introduced to the language in 1982~ish. Like I said, I used it extensively, attended and presented at APL conferences and…

> Not sure where to go from here.

For the past few years I've been telling people about the APL family of languages. The clincher for me was seeing the video of an APL version of Conway's Life mentioned in the submission. The impressive part wasn't its brevity, it was how they approached the problem.

In APL you have a 'rotate' operator that shifts data in a particular direction. If you have a vector and you rotate it once, every element moves to the next position and the last element then becomes the first.

The nice thing about APL is that most operations work on data regardless of its dimensionality. So, to do Conway's Life, you take your 2D matrix of cells and produce rotations of it in eight directions (N,NE,E,SE,S,SW,W,NW). You then take those rotated versions of the matrix along with the original and conceptually stack them. Then, for each grid point, you sum downward, producing a new matrix that contains the neighborhood count of the original matrix. From that you can create the next Life generation.

This sort of problem doesn't come up everyday, but the thing that I think is profound is that the existence of these operations allows us to think about problems in different, possibly simpler ways. They are untapped potential and they could be as well known as map and fold.

APL and its derived languages are hard to approach but there isn't much that keeps us from importing the data structures and operations in more approachable languages.

Re: A deep dive into APL

#25
post #8

The main problem with (GNU) APL for me is the line editor: I can't feel comfortable using a REPL to write a program without keybindings like ctrl-a, ctrl-w. Everytime I try to learn APL I eventually give up.

I don't know if this is helpful for you, but I map to run the open buffer in Vim in the buffer's filetype's interpreter (or compile and run, etc.). For GNU APL, this is:

  nnoremap   :write !cat - 
It took some time to figure that out, but combined with https://github.com/ngn/vim-apl, it is not too bad of an editing experience.

Re: A deep dive into APL

#26
post #4

Is APL still used for anything now? It seems like it could be a useful language for _something_.

I used to work at a large insurance company as an actuary, and although it's dying out, there's still APL code modeling insurance products in use. One of my jobs was to add the new years' assumptions into arrays.

Re: A deep dive into APL

#27
Looks like the site is hugged to death :-(

My only experience with APL-like languages was playing with K for a few months. It's amazing, no other language can do so much in a few characters. Here's a list of hundreds of snippets: http://code.kx.com/wiki/Qidioms

To give a taste of K style, I'll try to explain one of those snippets here. The problem statement is to merge three arrays x, y, z under control of another array g. Don't worry, it will make sense in a moment. These are the definitions of x, y, z and g, followed by one line of code solving the problem, and the result:

    x:"abcd"
    y:"123456789"
    z:"zz"
    g:"101121211010101"
    (x,y,z)[
First of all, (x,y,z) is just the concatenation of three arrays, and [] is the familiar array indexing operator. The twist is that [] can also accept an array of indices, so e.g. "ab"[0 1 1 0] returns "abba".

But the really clever bit is By any reasonable programmer's standard, that's way too much cleverness. But if you want a lot of functionality in a few characters, that's the price to pay, and K programmers seem happy to pay it. It's also really fast, because you're combining optimized bulk operations, and dropping down to individual elements only in special cases.

Re: A deep dive into APL

#28
post #4

Is APL still used for anything now? It seems like it could be a useful language for _something_.

Isn't the inventor of K+/Q currently writing his own operating system? Haven't heard any progress about that in a long time, hope it actually gets some use. Sure, won't be the next Linux, but maybe more than the next ColorForth.

Re: A deep dive into APL

#30
post #13

A+ a derivative of APL is still being used in a certain investment bank. 20 years of projects to deco it and replace it with something more modern haven't managed to completely kill it off yet. Main issue I had with it was the inability / cost to hire people with any experience, and the off-putting / steep learning curve. Once you get the hang of it though it's a great language for solving certain more numerically or…

Morgan Stanley. They open sourced it ~15 years ago at aplusdev.org. The project was led by Arthur Whitney, who went on to become Mr KDB.
Post reply on HN