Live data from Hacker News

A deep dive into APL

curtisautery.appspot.com

51–60 of 93 posts

Re: A deep dive into APL

#51

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 ar…

What do you gain from using the 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…

The function "grade up" has the symbol "
      ordinal: 
The idiom less explicit.

Re: A deep dive into APL

#52
post #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.

ColorForth is not an OS. For C. Moore, an Operating System is a non-thing.

Re: A deep dive into APL

#53

Earlier quoted context omitted.

"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 dist…

The 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 necessa…

Stuff 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...

Re: A deep dive into APL

#54

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 ar…

What do you gain from using the 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…

[deleted]

Re: A deep dive into APL

#55

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 ar…

  $ txr
  This is the TXR Lisp interactive listener of TXR 173.
  Use the :quit command or type Ctrl-D on empty line to exit.
  1> (let ((l '#"abcd 123456789 zz")
           (i '(1 0 1 1 2 1 2 1 1 0 1 0 1 0 1)))
       (gun (pop [l (pop i)])))
  (#\1 #\a #\2 #\3 #\z #\4 #\z #\5 #\6 #\b #\7 #\c #\8 #\d #\9)
Conversion to string:

  2> (let ((l '#"abcd 123456789 zz")
           (i '(1 0 1 1 2 1 2 1 1 0 1 0 1 0 1)))
       (cat-str (gun (pop [l (pop i)]))))
  "1a23z4z56b7c8d9"
What is this gun we have armed ourselves with? It stands for "generate until nil": it generates a lazy list whose elements are formed by successively evaluating the argument expression. If the expression yields nil then the list terminates (without adding that nil as an item).

The expression uses side effects. The pop macro is straight of ANSI CL. Except, in TXR Lisp, list processing stuff like `pop` works on other sequences such as character strings: we can pop the letter a out of a place which holds "abcd", leaving "bcd" in that place. This approach just "popped into my head" immediately.

We also have a syntactic [...] which gives us indexing (and other things).

We also have #"..." which is a "word list literal". Simply, #"foo bar baz" means ("foo" "bar" "baz"). Note there is no quote there to prevent the evaluation of this as a form; so we still have to use one.

I won't bother implementing the apparent requirement that the indices be digit characters from a string; I consider it a serious blemish on the language, if it's doing it implicitly. We can map a string of ASCII digits to the corresponding values like this:

  3> [mapcar chr-digit "01234"]
  (0 1 2 3 4)
Characters are characters, and numbers are numbers. Dynamic typing: yes please; daft typing: no thanks.

Re: A deep dive into APL

#56

Earlier quoted context omitted.

The 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 necessa…

Stuff 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,whic…

> handled by special code which runs a lot faster

This is just another way of saying "we don't have a compiler, so don't process data at the element level if you want speed".

It is not an advantage of the language, but a disadvantage.

If you have a compiler, then it's only valid for aggressive, machine-specific optimizations. This is articulated by statements like "the library function is marginally faster than an open coded loop, because it uses some inline assembly that takes advantage of vectorized instructions on CPU X".

If I write an FFT routine in C myself, it will not lose that badly to some BLAS/LAPACK routine.

Re: A deep dive into APL

#57
post #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.

Complete USB host driver for Intel EHCI:

  #(*
The << idiom really stands out here.

Re: A deep dive into APL

#58

I really liked the way that Iverson built up concepts in his [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.

I thought they were great too!

Re: A deep dive into APL

#59
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.

Mr. Moneybags...well earned from what I hear.

Re: A deep dive into APL

#60

Earlier quoted context omitted.

It'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-foo...

Second 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.

"SciPy – the embarrassing way to code"

http://www.vetta.org/2008/05/scipy-the-embarrassing-way-to-c...

Post reply on HN