12 ms·
A deep dive into APL
- fernly 10y agoNice to see APL lives and people still try to teach it. For software historians, all the 1970s-era manuals are at bitsavers[1]. The language was quite a bit simpler then; several of the primitives this tutorial thought appropriate to introduce didn't exist then. [1] http://www.mirrorservice.org/sites/www.bitsavers.org/pdf/ibm/apl/ http://www.mirrorservice.org/sites/www.bitsavers.org/pdf/ibm...
- gionn 10y agoIs this sorcery?
- Semaphor 10y agoIt's APL. First time I heard about it was in those "how to shoot yourself in the foot" lists [0]: * You shoot yourself in the foot and then spend all day figuring out how to do it in fewer characters. * You hear a gunshot and there's a hole in your foot, but you don't remember enough linear algebra to understand what happened. [0] http://www.toodarkpark.org/computers/humor/shoot-self-in-foot.html http://www.toodarkpark.org/computers/humor/shoot-self-in-foo...
- throwaway7645 10y agoSecond bullet point is pretty funny. I really liked linear algebra, but I'm sure it could get frustrating if you're not an expert. I wonder if it makes sense philosophically for code to be more mathematical like APL or like a spoken language like Python.
- GregBuchholz 10y ago"SciPy – the embarrassing way to code" http://www.vetta.org/2008/05/scipy-the-embarrassing-way-to-code/ http://www.vetta.org/2008/05/scipy-the-embarrassing-way-to-c...
- throwaway7645 10y agoI enjoyed this article. Thanks!
- ColanR 10y agoIs APL still used for anything now? It seems like it could be a useful language for _something_.
- evincarofautumn 10y agoI dunno how widely used it is, but there is Kdb+[1], “a column-based relational time-series database” built on the K[2] language, a descendant of APL. I mainly see J[3] used for code golf, but at least that means a decent number of people know it. [1]: https://en.wikipedia.org/wiki/Kdb%2B https://en.wikipedia.org/wiki/Kdb%2B [2]: https://en.wikipedia.org/wiki/K_(programming_language) https://en.wikipedia.org/wiki/K_(programming_language) [3]: https://en.wikipedia.org/wiki/J_(programming_language) https://en.wikipedia.org/wiki/J_(programming_language)
- RyanHamilton 10y agokdb is great, basically it combines an APL like language and a database, which is very cool as you can easily push your calculations to where your data lives: http://www.timestored.com/kdb-guides/kdb-database-intro http://www.timestored.com/kdb-guides/kdb-database-intro If you want to dive in and try it, I've also made a video tutorial here: http://www.timestored.com/kdb-guides/getting-started-kdb http://www.timestored.com/kdb-guides/getting-started-kdb Even if you don't use it, it's an interesting language to study as it's significantly different to the common java/python etc. The one drawback is that for commercial use it's very expensive. Other "modern" APL like languages that are available free include J and kona (open source K).
- alfalfasprout 10y agoKdb+ is incredible. It blows away any of the current attempts at time series data stores out there (eg; InfluxDB, OpenTSDB). Unfortunately, Kx Systems failed to allow it to reach mass popularity by keeping licenses extremely expensive. Startups simply can't afford to outlay $100k+/year for a tiny cluster.
- avmich 10y ago
- sunkencity 10y agoThe core language is good enough but the object oriented stuff they put on top later on is just a hell of an eyesore.
- rnhmjoj 10y agoThe 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.
- bjarkevad 10y agoI haven't tried it out, but maybe rlwrap can help here.
- rnhmjoj 10y agoUnfortunately it doesn't seem to work.
- lokedhs 10y agoI implemented Emacs support to handle exactly this. It also provides several other useful features such as formatting and code navigation. It's available on MELPA as gnu-apl-mode, or you can get it here: https://github.com/lokedhs/gnu-apl-mode https://github.com/lokedhs/gnu-apl-mode As poor as this video is (and the last time I posted it I believe I said I was going to make a new one), it does illustrate some of the features: https://www.youtube.com/watch?v=yP4A5CKITnM https://www.youtube.com/watch?v=yP4A5CKITnM
- deleted 10y ago[deleted]
- oinksoft 10y agoI don't know if this is helpful for you, but I map <c-p> 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 <buffer> <C-P> :write !cat - <(echo ")OFF") \| apl --script<CR> It took some time to figure that out, but combined with https://github.com/ngn/vim-apl https://github.com/ngn/vim-apl, it is not too bad of an editing experience.
- rebootthesystem 10y agoI 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.
- n17 10y agoThis is really interesting! What are your thoughts on the J language as an evolution of APL?
- rebootthesystem 10y agoJ 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.pdf 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.
- adamaid 10y agoA+ 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 orientated problems.
- osullivj 10y agoMorgan 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.
- throwaway7645 10y agoMr. Moneybags...well earned from what I hear.
- beagle3 10y agoWould you be able to comment about how much of it is the underlying APL (and math coded therein), and how much of it is the Electric GUI ?
- leoc 10y agoI'm just going to leave this here: http://www.ccs.neu.edu/home/shivers/papers/rank-polymorphism.pdf http://www.ccs.neu.edu/home/shivers/papers/rank-polymorphism...
- jtraffic 10y ago"APL, and its successor J [...] provide a notational interface to an interesting model of computation: loop-free, recursion-free array processing." How is APL loop-free, exactly? Later they say: "Under this implicit lifting, the iteration space is the argument frame rather than a sequence of loop indices." So if I understand correctly, we have iteration, but no loop. But that doesn't seem like a really important distinction...what am I missing?
- RodgerTheGreat 10y agoThe key feature is abstract iteration, like functional maps, filters and folds, and implicit iteration, where operations "penetrate" to the items of a vector or matrix automatically, rather than explicit iteration like a "for" loop. Abstract iteration is useful because it results in programs with fewer "moving parts"- no loop induction variables to misplace or mutate in the middle of a loop body. Programs are necessarily expressed in a more rigid manner and some irregular algorithms can be difficult to express. Summing a vector with an explicit loop in K (very non-idiomatic!): r:0;i:0; do[#v;r+:v@i;i+:1]; r The equivalent using the "over" adverb: +/v Both examples perform the same calculation. The latter is more concise and easier to reason about.
- jtraffic 10y agoI see. Good answer.
- scottlocklin 10y agoStuff like +/v is easier to reason about, but it's also handled by special code which runs a lot faster. At some point I need to do a blog on all the horrible things that happen inside your computer (cache hits, memory being swapped in and out, stacks popping) when you do an interpreted, explicit loop; bytecode, AST or whatever. There are R&D interpretors which claim to remove this overhead for trivial for loops,which are the main kind that end up getting used in numeric code, but none of them ever seem to make it into production (I'm sure someone will correct me if I am wrong; I am pretty sure Art wasn't doing this in K4, though he was probably best positioned to do so). The real reason we like +/v besides less typing; it can be handled with special code which runs close to the theoretical machine speed. Lots of small places and languages this fact can be exploited in. R and Matlab basically have a subset of operations you can do +/v type things with. APL is the main class of languages where this sort of thing is built into the semantics of the language. If you're dealing with numerics in an interpreted language, it should be built into the semantics of your language, and that's how you should do things. Really it should be in compiled languages too, and that's how people should reason about code, but it's probably asking too much since APL has only been around since the 70s...
- muraiki 10y agoI'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 https://webdocs.cs.ualberta.ca/~smillie/Jpage/jtsp.pdf [2] http://archive.vector.org.uk/art10501700 http://archive.vector.org.uk/art10501700
- ceautery 10y agoSorry, everyone, looks like choosing to host my site on appspot was incongruous with high traffic, since I only get 1 gig of outgoing bandwidth per day. Here's the cache: https://webcache.googleusercontent.com/search?q=cache:K-e7JhLlJ4YJ:https://curtisautery.appspot.com/5776042744610816+&cd=1&hl=en&ct=clnk&gl=us https://webcache.googleusercontent.com/search?q=cache:K-e7Jh...
- cousin_it 10y agoLooks 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 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)[<<g] "1a23z4z56b7c8d9" 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 <<g. A single invocation of < returns the sorting permutation of an array, i.e. an array of indices x such that g[x] is sorted. After two invocations of < you get the sorting permutation of the sorting permutation. In other words, the inverse of the sorting permutation. In other words, the permutation that turns sorted g into regular g. In other words, exactly the permutation that you need to mesh x, y and z together! 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.
- pmoriarty 10y agoWhat do you gain from using the << syntax over a verbose but reasonably clear function name like "sorted-permutation"? Clarity in function names is one of the main reasons I prefer Lisp and Scheme over languages like APL, K, and Haskell, which seem to favor the use of something like a mathematical notation, which I've always found obfuscating. This obfuscation is made worse by the aversion to comments that I've seen in some of these languages, while in Lisp and Scheme, the verbose and explicit function names are in a way self-documenting. For someone who prefers a clear and explicit programming style, the terseness of some programming languages is a real turnoff.
- 10y ago
- jtraffic 10y agoI thought it was super cool when I found out you could overload operators in Julia. I wonder if you could re-create some APL-like syntax that way.
- KenoFischer 10y agoYou might enjoy this one: https://www.youtube.com/watch?v=XVv1GipR5yU https://www.youtube.com/watch?v=XVv1GipR5yU
- jtraffic 10y agoI really did enjoy that. It reminded me of how I use R and then drop down to C++ when I need speed. This interpreter is analogous: use Julia and then go to APL when you want compact expression. Although, I'm not sure how advantageous it is. At least prima facie it's not as compelling as the speed gains you get from dropping to C++ from R.
- mmcclellan 10y agoI really liked the way that Iverson built up concepts in his [Arithmetic (PDF)](http://www.jsoftware.com/books/pdf/arithmetic.pdf http://www.jsoftware.com/books/pdf/arithmetic.pdf) manual for J. I found it very intuitive and useful even if you never plan to use the language. There are others at the site like his manual for Exploring Math and one for Calculus as well.
- throwaway7645 10y agoI thought they were great too!
- dang 10y agoThis recent thread about an APL compiler for the GPU was so interesting: https://news.ycombinator.com/item?id=13565743 https://news.ycombinator.com/item?id=13565743, that we invited the author to do an AMA about it: https://news.ycombinator.com/item?id=13797797 https://news.ycombinator.com/item?id=13797797.