News for hackers. Stuff that matters.
Re:A deep dive into APL by rebootthesystem on Tuesday March 28, 2017 @04:44AM (#13975059)
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 even have a picture of my younger and dorkier self with Ken Iverson (creator of APL).

This struggle to run on hardware that could not handle the huge expansions and contractions of memory utilization inherent in the way APL works multidimensional data sets like putty meant it could not compete where other languages had no issues at all. On PC's you were limited to 640K of RAM. It would be years before you could have enough memory to almost not care about utilization.

As the language didn't really catch the attention of the CS masses it failed to evolve as it could have over the years. And this is the reason I would suggest today it is not much more than a curiosity.

I'm sure there are some out there using it professionally. If I were to guess i'd say it must be mostly companies with a significant installed based of APL software they don't dare try to rewrite.

I firmly believe that the future of computing has to be in an APL-like language. By this I mean that we need to evolve to a notation for computing, rather than text for computing. Iverson himself wrote an excellent paper titled "Notation as a Tool for Thought".

The issue is that in order to evolve APL one has to have a deep understanding of APL. And, frankly, there are but a few of us around who have that understanding. Not sure how many of this group would embark on the mission to create a true next-generation APL worthy of it's lineage.

I read and I smile every time I see the language come up on HN. I taught my kids some APL and they are always blown away by it. Not sure where to go from here.

Re:A deep dive into APL by michaelfeathers on Tuesday March 28, 2017 @08:51AM (#13976109)
> 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 by nickpeterson on Tuesday March 28, 2017 @09:56AM (#13976564)
Hey Michael, been a fan since reading 'Legacy Code'.

Do you believe that refactoring a large APL codebase would be inherently easier than something like, a large legacy C++ codebase?

What is the relative complexity of comparing, say 1000 lines of APL to 10K lines of C++?

I remember reading an interview between Arthur Whitney and Bryan Cantrill where they mentioned something about recognizing idioms in the dense code much more easily in K than in something like C because it took so many less characters. Do you see any sort of refactoring advantage to that?

I've also recently seen work on the Co-dfns compiler in APL where the author mentioned that APL allowed him to easily refactor compared to traditional codebase, and looking at the github library, there is something like 3 million edited lines over the span of several years in a codebase this is a few thousand lines of code. I find this fascinating because my hope is to eventually start a small software business and I think reducing complexity in the number one priority in order to make it sustainable in the small (the goal isn't to have a team of 50 developers).

Thoughts?

Re:A deep dive into APL by michaelfeathers on Tuesday March 28, 2017 @11:39AM (#13977510)
Nick, I think that the primary win is referential transparency. APL idioms raise the level on that base. The tradeoff, though, is the same as we have for functional but further along the road: if you develop a codebase that doesn't use common idioms it's harder to hire people to work in it.

I think array languages, or at least their operation set and idioms, will move into the mainstream in the same way that functional is, but it will take time. Sustainability for your business would be more an issue of hiring and retaining talent.

Reach out if you want to talk about this more: @mfeathers

Re:A deep dive into APL by rebootthesystem on Wednesday March 29, 2017 @03:09AM (#13984060)
Exactly. Hence the idea of notation as as tool for thought.

APL makes you see and envision computational problem solving differently than, say C. Use it enough and your brain starts thinking in patterns, shapes, vectors and matrices being "zippered" together or apart, contorted and distorted.

Take a matrix of values and hit it with another matrix of 1's and 0's to select elements and then flip it, slice it, convert it to a vector and combine it with another vector to form a new matrix, then scale every element and apply a polyphase FIR filter across the rows using another matrix for the coefficients to then arrive at a vector containing your answer. This is made-up, of course, but that's how you start thinking, you start seeing parallel computing in your head and you can reach for it instantly with a notation that allows your hands to describe what you just imagined with a few well-selected symbols. No other language sends you on these flights.

It is truly seeing and approaching computational problems from a very different perspective. And the notation makes it comparable to composing music rather than going through the ugly mechanics of text-based programming languages.

I find it hard to explain to those who have never experienced this revelation of sorts. Watching a few videos and playing around with APL isn't enough. If I had to guess I'd say someone would have to work with it on a daily basis for about a year to achieve that mental shift.

Again, no different from musical notation. It is impossible to explain or experience how you see music once your brain can look at a page full of funny symbols and your mind starts to hear the music. The relationship with the piano, guitar or other instrument changes once that mental connection requires no thought at all.

Getting there with APL takes time. For example, you need to be able to sight read idioms like thee following much as a musician learns to read a two hand chord and instantly place their fingers exactly as required on the piano, without though.

http://docs.dyalog.com/14.0/Dyalog%20APL%20Idioms.pdf

or a large enough subset of these:

http://aplwiki.com/FinnAplIdiomLibrary

Back then, a lot of us used to walk around with a small pocket-sized FinnAPL idiom book in our pocket and had the FinnAPL idiom library book on our desk.

Re:A deep dive into APL by muraiki on Wednesday March 29, 2017 @09:34PM (#13992188)
Your comparison to musical notation is insightful. I think that I can expand upon it a bit. I can read both western notation and Byzantine notation. Byzantine notation is very different from western notation: it describes a melody using symbols indicating how many steps to take from the current pitch in a given scale. There are also rhythmic symbols added to the notes that generally require reading ahead of what you are currently singing.

For people interested in Byzantine music, the notation can seem imposing at first -- especially to people who already know western notation. Much effort has gone into translating Byzantine music into western notation, but some problems arise. First, some Byzantine scales use very different pitches compared to a western equal tempered scale. Second, the rhythms in Byzantine music can involve syncopation or other rhythms that can be difficult to notate using western rhythmic symbols. Finally, Byzantine notation is optimized for depicting melody, while western notation is focused on harmony. There is simply more unnecessary visual noise in writing Byzantine music in western notation.

That last point resonates with your talk of idioms. While Byzantine music may seem to have many neumes for a given musical phrase, there are many idiomatic combinations of pitch-changing and rhythmic neumes together. As such, what would be read in Western notation with many individual notes and rhythmic markings, becomes in Byzantine notation a single "word".

If you're interested in seeing how these systems of notation compare, look at the following hymn: http://www.cappellaromana.org/wp-content/uploads/2014/04/Che... The neumes are in red at the top, with a simple western interpretation on the first western music staff and an ornamented interpretation on the bottom staff. Comparing the neumes to ornamented western interpretation (which represents the full Byzantine ethos, or style), we can see that significantly more information is contained in the sparser Byzantine neumes.

Anyway, you've convinced me to learn APL because I now see how similar the arguments for this notation are to my own arguments for using Byzantine notation. Thank you for your insight.

Re:A deep dive into APL by rebootthesystem on Thursday March 30, 2017 @02:45AM (#13993440)
This is very interesting. I sight read western notation but never learned anything else. To be honest, I didn't even know Byzantine notation existed. Time to go learn something new. Thanks!
Re:A deep dive into APL by pmoriarty on Tuesday March 28, 2017 @12:27PM (#13978013)
I would really love to read an expanded version of this explanation, as it's not clear to me why or how stacking or summing rotated matrices would work for this problem.
Re:A deep dive into APL by mbudde on Tuesday March 28, 2017 @12:54PM (#13978279)
Take a look at this explanation on the APL wiki: http://aplwiki.com/GameOfLife
Re:A deep dive into APL by n17 on Tuesday March 28, 2017 @05:58AM (#13975315)
This is really interesting! What are your thoughts on the J language as an evolution of APL?
Re:A deep dive into APL by rebootthesystem on Wednesday March 29, 2017 @03:28AM (#13984132)
J and other variants were bad ideas and continue to be bad ideas. They abandon one of the more powerful aspects of APL: Notation.

Here's a paper by Ken Iverson about the power of APL notation:

http://www.eecg.toronto.edu/~jzhu/csc326/readings/iverson.pd...

Why does J exist?

Back in the mid 80's (I don't remember exactly) dealing with APL on IBM PC's was not easy. You really had to want to run APL.

For example, we had to hack the equivalent of today's graphics card to replace the character ROM with one programmed to display APL characters. The more advanced modification allowed you to throw a mechanical switch and go between APL and non-APL characters.

Printing APL characters required using very specific printers and changing the print wheel or ball (IBM printers) with versions having APL characters.

Again, you really had to want to run APL to endure this. And, that, of course, affected adoption. You couldn't run APL on any random IBM PC or clone on a desk.

So, Iverson, despite identifying notation as one of the more powerful features of APL, ends-up "going commercial" by transliterating APL symbols into combinations of ASCII characters. Now you could run something that behaved like APL on any computer. And, of course, it was a complete abomination. Terrible thing.

I think I can say the APL community rejected J almost universally. Doing this was a terrible idea. And a short-sighted one at that. It wasn't long til all computers had the ability to display expanded character sets and eventually full graphical canvases where anything was possible.

J was a commercial reaction to a hardware problem that evaporated very quickly. J was not a commercial success for reasons obvious to those of us who used APL professionally every day for years: It was a hot mess and almost diametrically opposed to what made APL so incredible to use in solving problems through computing.

I would stay far away from J. As brilliant as Iverson had to be to create APL when he did, J, as far as I am concerned, was an almost unforgivable mistake.

Re:A deep dive into APL by muraiki on Wednesday March 29, 2017 @10:00PM (#13992291)
You mentioned in another comment that if APL is to go anywhere, that it needs to be open sourced. Unfortunately, the cost of Dyalog and the fact that it is closed source are the main reasons why I've ended up using J.

I appreciate that Dyalog is free for non-commercial use, but I think that part of what makes a programming language successful is if people can start using it in small ways to make their work better. For instance, at my previous job we started using Go for small things and it eventually took on a larger role once we saw how well it worked out in practice. Had we needed to pay to use Go for those small things, we never would have even tried it in the first place. I realize that the Dyalog company needs to actually make money somehow, but I wonder if they are aware of this problem. I did email Dyalog to see if using Dyalog for my work at a non-profit constituted commercial use, but they said that it did. :(

Edit: The reason why I haven't used GNU APL is because it seems like getting it to work under Windows will be difficult, and my work is unfortunately a Windows environment. Maybe I should give it a shot anyway.

Re:A deep dive into APL by rebootthesystem on Thursday March 30, 2017 @11:57PM (#14001070)
Try NARS2000. It's APL with sensible extensions written by someone who knows APL very well.

http://www.nars2000.org/

Re:A deep dive into APL by throwaway7645 on Tuesday March 28, 2017 @06:24AM (#13975412)
You ever try the modern Dyalog offering with .NET, SQL, and R interop? Pretty cool stuff although I don't really use the language. There is a guy here writing a compiler for Dyalog APL that runs on a GPU, but is only a few pages of APL. If that isn't the future, I don't know what is.
Re:A deep dive into APL by rebootthesystem on Wednesday March 29, 2017 @03:47AM (#13984198)
No, I haven't sorry. I agree with the other comment in that APL, if it is to go anywhere, needs to be open sourced. I'll go beyond that and say that what we need is a new iteration of APL that addresses all the issues with a language that is now at least 30 years away from its most active and innovative period. That's a tall order. I can see getting into something like that as a retirement project. Way too much other good stuff to do now.
Re:A deep dive into APL by throwaway7645 on Wednesday March 29, 2017 @06:42AM (#13984872)
That'd be a nice project. It's not APL, but I wanted to add that Perl6 has some APL features such as letting you define custom operators using any Unicode symbol you like, so you could technically write an APL language on top really easily. I wonder if more APL features will pop up in other languages in the future.
Re:A deep dive into APL by FractalNerve on Tuesday March 28, 2017 @03:13PM (#13979693)
I also think it's the future, the problem is that I don't believe that Dyalog APL is the future, even though it's really nice. It just should be opensource to succeed imho., why still be so greedy and take money for a language. Also the IDE is really weird. I love APL and J, but I think there is a lot of space for improvement. And I want that improvement to happen in the open. They can still charge for Consulting, Hosting whatnot.
Re:A deep dive into APL by throwaway7645 on Tuesday March 28, 2017 @06:49PM (#13981568)
I'm curious if it would be so nice as a non-commercial project. I suppose some companies would still pay for support and development.
Re:A deep dive into APL by FractalNerve on Thursday March 30, 2017 @09:08AM (#13994988)
You mean a funding model similar to FreeBSD, right? With the right partnerships this could indeed work very well. At a time where even Microsoft opensources their compilers, Dyalog keeping theirs from the ~70s closed is mind bending to me.

And I agree, I would pay, even if it's not that much. The commercial license comes with a too steep price tag. I'd rather opensource my code or contribute where I can.

Re:A deep dive into APL by pmoriarty on Tuesday March 28, 2017 @12:24PM (#13977980)
Lisp was also far ahead of its time, but many Lisp features like garbage collection and lambdas have made it in to mainstream programming languages. Has anything similar happened with APL?
Re:A deep dive into APL by muraiki on Tuesday March 28, 2017 @02:59PM (#13979552)
An article[1] claims Wes McKinney was inspired by APL while working on pandas; some of the pandas verbs such as "ravel" come from APL.

Also, the <- instead of = in R comes from APL, although that's relatively minor. :)

[1] https://scottlocklin.wordpress.com/2013/07/28/ruins-of-forgo...

Re:A deep dive into APL by rebootthesystem on Wednesday March 29, 2017 @03:32AM (#13984147)
Interestingly enough, I was working with APL, Lisp, Forth and C pretty much simultaneously during my ten year or so sting using APL professionally.

This was an amazing combination of languages to have in my toolbox simultaneously. The mental calisthenics alone were truly enjoyable to me.

Re:A deep dive into APL by baldfat on Tuesday March 28, 2017 @02:55PM (#13979523)
I just think of Lisp as its own world. They had to build Lisp machines to work on machines in years past. Today we still see growth in Lisp and seeing how Racket is developing and Clojure shows that Lisp has room to continue to innovate.