
A History of APL in 50 Functions - jim-jim-jim
http://www.jsoftware.com/papers/50/
======
evincarofautumn
I wonder if array languages will find wider popularity some day with a bit
more verbose notation. Take “Array Indexing” (#29):

    
    
        {(,⍺)[(⊂⍴⍺)⊥¨⊃∘.,/⍵]}
    

Or “Inverted Table Index-Of” (#31):

    
    
        (⍉↑x⍳¨x) ⍳ (⍉↑x⍳¨y)
    

These could be written:

    
    
        {(reshape lhs)[(enclose shape lhs)
          polynomial each disclose
          outer product reshape reduce rhs]}
    
        (transpose take x index each x)
          index (transpose take x index each y)
    

Same terms, just with searchable words instead of symbols. (Don’t mind the
specific words—I’m not much of an APL user!) It definitely sacrifices some
important aspects of APL, but in exchange I think it gains something in terms
of accessibility by explicitly writing the pronunciations you might have in
your head anyway when reading & writing the symbolic notation. It also
encourages extracting reusable named definitions instead of repeatedly writing
“idioms”.

~~~
segmondy
You can assign a name to each of those symbols if you want and have something
equivalent to what you just wrote.

tranpose=:⍉

take:=↑

index=:⍳

each=:¨

done, now I can write (⍉↑x⍳¨x) as (transpose take x index each x)

But the entire idea of APL is notation as a tool of thought.

Would you write read your maths as five plus twenty is equals to twenty five
or 5 + 20 = 25?

Would you rather read music with it's musical notiation

or quarter note at middle C, quarter note at middle E, etc?

The entire idea of APL is that we read and write algorithms the way we read
mathematical and musical notes.

~~~
FPGAhacker
That’s a pretty good analogy, the 5 + 20 example.

By using abstract symbols, it encourages one to skip the internal
verbalization and go straight to the concept. Pretty neat.

But in the article, they use symbols that I don’t have on my keyboard. I guess
one would learn the combination for such symbols and become fluent to the
point that it didn’t matter. For example, I don’t think of the individual
letters when I’m typing.

Although my highschool typing class strongly encouraged doing so. I believe
that was more for maintaining a rhythm, however.

~~~
Jtsummers
Earlier this year I took a deep dive into APL (something I'd been meaning to
do for a while). With Dyalog APL and the APL mode in emacs, typing these
things in is pretty easy and becomes natural if you're already a touch typist.

For instance, iota is just `.i`, rho is `.r`, etc. Some are more natural (like
that) others are arbitrary but logically consistent, like take and drop are
next to each other on the keyboard.

After a few days I felt like I could type _most_ programs without having to
think about where keys were. Admittedly, I've lost it all now since I haven't
touched it for a couple months. If I actually stuck with it for more than the
4-6 weeks I did I imagine I wouldn't have lost it so quickly.

~~~
untangle
> APL mode in emacs, typing these things in is pretty easy...iota is just
> `.i`, rho is `.r`, etc.

...and iota is just `i and rho is `r in the Dyalog editor. So non-emacs folks
can play too.

~~~
Jtsummers
Ah. You’re right. I had changed the prefix in Dyalog to match emacs since
that’s what I’d started with.

------
textmode
APL was designed to be taught to non-programmers. Indeed it was taught in some
high school maths classrooms.

I have been reading many books and other historical documents on APL from the
1960s/70s/80s and this one I found to be especially interesting:

[http://www.softwarepreservation.org/projects/apl/Papers/Elem...](http://www.softwarepreservation.org/projects/apl/Papers/ElementaryAlgebra)

I would like to thank the HN user who has posted this a couple of times. I am
grateful for this resource and reading it sooner rather than later.

Why I found this particular publication unique amongst all the others I have
read:

It is many pages before the reader encounters any _programming jargon_. I
believe the use of the term "primitives" may be the first slip.

It is possible the reader with absolutely no familiarity with programming
would not be alienated by any of the terminology Iverson uses. That is
uncommon for an expository text by an author who knows how to program, in my
experience as a reader.

Perhaps terminology was carefully chosen with a view to avoiding programming
jargon and letting the _symbols_ (notation) and _example input and output_
communicate the concepts.

Here is another question:

Matrix multiplication can play an important role in so-called "AI" or "Machine
Learning". For example, Hopfield networks.

The extraordinarily popular Python language, specifically the "NumPy" library,
is frequently cited on HN.

How suitable or unsuitable is APL for matrix multiplication and, by extension,
"Machine Learning"?

Assuming in each case a programmer competent in her chosen language (i.e.
ignoring the competencies of the programmer), which language has faster
execution times, Python or APL?

~~~
geocar
> How suitable or unsuitable is APL for matrix multiplication

Matrix-multiply is just plus-dot-times or +.×

> which language has faster execution times, Python or APL?

This is tricky to answer. For most problems, I'd say APL, but this is isn't
quite fair.

A competent Python programmer who has made it "as fast as possible" without
resorting to extensions will be creamed by a novice APL programmer, so you
_need_ to consider third-party modules like NumPy just to compete.

Now NumPy is _very_ well-optimised, but you'll really struggle to do well
against k/q[1] an APLish that actually focuses on performance, and if you run
into a problem where it doesn't, there are extensions you can use to eke out
even more performance.

At this point, you might try using Tensorflow -- which gives Python a great
edge -- but are we really programming Python anymore? kdb+ can use Tensorflow
as a library as well...

[1]: [http://tech.marksblogg.com/billion-nyc-taxi-
kdb.html](http://tech.marksblogg.com/billion-nyc-taxi-kdb.html) fastest non-
GPU

~~~
JulianMorrison
It's a style difference between "optimized C and ASM kernels wrapped in a slow
heavyweight language" and "a very simple interpreter that fits in cache".
Circumstances are probably going to drive which approach wins out.

------
untangle
For those wishing to learn this mysterious language, Dyalog has an excellent
online tutorial at:

[https://tutorial.dyalog.com/](https://tutorial.dyalog.com/)

Using this tool, I was "thinking APL" (at a novice level) in a couple of days.

Dyalog also has a free-for-personal-use 64-bit version.

~~~
kasbah
Thanks for the link. Do you know if there is something similar for GNU APL?

Do you think it will be annoying to switch to GNU APL after going through
this? I'd rather not spend time learning a proprietary interpreter if there's
a viable free software alternative.

EDIT: Have started going through the tutorial using the GNU APL interpreter.
I'll see how it goes I guess. 2+5 seems to work the same :)

EDIT 2: akt makes it possible to type the symbols without a special keyboard
with GNU APL
[https://github.com/TieDyedDevil/akt](https://github.com/TieDyedDevil/akt)

~~~
Avshalom
For that tutorial the only problem you might run into is multiple statements
or recursion in dfns (bracketed functions)

~~~
kasbah
Thanks, I'll try and keep an eye out for that.

EDIT: There is a smaller thing I noticed: a function on its own is a syntax
error in GNU APL (and they can't be assigned to variables either).

------
Avshalom
Well this is just fucking gorgeous.

~~~
tluyben2
I was looking for more subtle words, but you are absolutely right. Great work.

------
sxp
When reading APL for the first time, how does one determine what the
characters mean? E.g, the first example is (+⌿÷≢) x

I can look up the '+' '⌿' '÷' characters at
[https://en.wikipedia.org/wiki/APL_syntax_and_symbols](https://en.wikipedia.org/wiki/APL_syntax_and_symbols)
but I can't find the "≢)" characters which appear to be the '≢ ' and ')'
characters when I copy and paste. However, I see it as '≡' '/)' when rendered.
Is that broken Unicode rendering of the slash? I'm guessing this function
means something like (divide (reduce sum array) (count array)) but I can't
search for that triple equal sign on the Wikipedia page.

~~~
untangle
>how does one determine what the characters mean?

Download (free) Dyalog APL. Mouse-over any character in the editor and a mini-
man page pops up.

Or use this cheat sheet:

[http://docs.dyalog.com/16.0/ReferenceCard.pdf](http://docs.dyalog.com/16.0/ReferenceCard.pdf)

------
gtani
APL and C were my first languages, but I can't read most of those, it's been
too long.

Merrill Lynch's mortgage operation was an IBM APL2 shop with a few dozen
programmers, along with people doing non-mortgage stuff.

[http://www.thocp.net/software/languages/apl.htm](http://www.thocp.net/software/languages/apl.htm)

[https://en.wikipedia.org/wiki/APL_(programming_language)#APL...](https://en.wikipedia.org/wiki/APL_\(programming_language\)#APL2)

I remember that people who came from the other dialects, Sharp and STSC, had
different ways of doing e.g. nested arrays and calling out to the OS which
made their code hard to read.

------
neves
I programmed in APL! When I was doing my masters, I worked with an IBM
researcher who had some old code in APL that I had to modify.

It is completely crazy. I originally had a special keyboard with all the
symbols: [http://i.imgur.com/8kOZkEX.jpg](http://i.imgur.com/8kOZkEX.jpg)

I needed to print a keyboard mask to put over the keys to remember where to
type. After sometime you get used to it, but it is too much overload in your
working memory when you are learning it.

The vector operations were really nice and the notation made it succinct, but
packages like pandas are far better.

It is impressive how usability were not a factor considered when some
languages were developed.

~~~
pradn
Perhaps we should have different keyboards for programming. Traders have
Bloomberg terminals. Why shouldn't we have an APL keyboard if we're using that
language? If language is a tool of thought, then the input devices reduce time
to putting that thought into action.

~~~
mmphosis
[https://www.dyalog.com/uploads/images/Business/products/uk_r...](https://www.dyalog.com/uploads/images/Business/products/uk_rc.jpg)

------
textmode
(Novice k user)

Exercise: Download to a single html page using k3 and curl

cat 1.k

    
    
       c:"curl http://jsoftware.com/papers/50/";
       f:("intro";"50_";"chrono";"pers";"fine";"ref";"ack")
       e:".htm;sleep 3"
       a:{,/$(c,:[x=0;f[1],f[0];f[1]],:[x>49;f[x-48]],:[x<10;:[x=0;;0,x];:[x>49;;x]],e)}'!55
       {`4:a[x]}'!55
    

k 1 > 1.html

firefox file:///1.html

~~~
RodgerTheGreat
A few simplifications:

    
    
        c:"curl http://jsoftware.com/papers/50/50_"
        e:".htm;sleep 3"
        f:{("intro";"chrono";"pers";"fine";"ref";"ack";-2#"0",$x)0 50 51 52 53 54?x}
        {`4:c,f[x],e}'!55
    

The pattern of using find and indexing into a table with a default case is a
nice way to get rid of lots of twisty conditionals.

------
peter303
My MIT analog circuits course in 1973 used APL. I dont know what they use now.

~~~
todd8
I took the same course! I remember that we had been taught to calculate the
voltages and currents for all points in an electrical network as vector
algebra operations. Then, for one of our assignments we were expected to just
learn APL on our own to write a program to do these calculations. As I recall,
it wasn't too difficult using APL.

I believe that we were given or used some sort of IBM manual to learn APL. I
just searched my library and found _APL /360 An Interactive Approach_ by
Gilman and Rose, 1970[1]. However, APL was most definitely not the focus of
the course so I think this was a book I bought a couple of years later in grad
school for myself.

We wrote the programs on a fancy version of a teletype machine, made by IBM,
called the IBM/360 APL Terminal System. See the photos of the paper based
terminal in [2].

[1]
[http://www.softwarepreservation.org/projects/apl/Books/Gillm...](http://www.softwarepreservation.org/projects/apl/Books/GillmanAndRose)

[2] [http://thenostalgicgeek.blogspot.com/2013/09/resurrecting-
ap...](http://thenostalgicgeek.blogspot.com/2013/09/resurrecting-apl360.html)

------
navium
There's not a single code snippet listed on Wikipedia.

------
Jtsummers
[http://www.jsoftware.com/papers/50/](http://www.jsoftware.com/papers/50/)

This link gives you the navigation panel on the left. Makes it a bit easier to
peruse.

~~~
sctb
Thanks! We've updated the link from
[http://www.jsoftware.com/papers/50/50_intro.htm](http://www.jsoftware.com/papers/50/50_intro.htm).

------
kierenj
Took me about a minute: click ">>" in the top-right of the page.

edit: Oh.. reloaded and a side nav appeared. Probably just me then.

~~~
sqlacid
the joys of frameset

~~~
coldtea
As if frameset is generally unreliable?

~~~
hk__2
Framesets totally break the accessibility of a website. The main website is in
one frame, and its navigation in another one. Both frames have different
contexts and different URLs.

~~~
coldtea
That's only true if screen readers haven't adopted to framesets.

With the popularity of the latter for 20+ years of early web, they're totally
fine with them (as they are with tables for layout, and many other things
people believe "break accessibility).

------
wfwefwef32
I have no idea of what APL is, and the thing doesn't even bother explaining
it.

~~~
sbmthakur
Why is this downvoted? I had the same problem and I am certain many others
faced it too.

~~~
kyberias
Substitute e.g. Python or C++ for APL. Do you still think the articly should
explain that "C++ is a programming language."

~~~
goatlover
It's probably because APL doesn't look anything like your typical PL.

~~~
deathanatos
Which — once you're acquainted with its existence — is the very thing that
makes it instantly recognizable.

