
APL – A Glimpse of Heaven (2006) - lelf
http://vector.org.uk/art10011550
======
willvarfar
An anecdote about my first and only brush with an APL programmer:

Towards the end of the nineties I was a young computer science student
standing on an almost deserted suburban above-ground underground station
waiting for the next train into the centre of London.

A very old but brisk and snappy gentleman in traditional gentleman's clothes
came onto the platform, and for some reason we nodded genially as you do when
you pass strangers on country lanes; in London you ignore absolutely everyone,
so it was strange we did this.

And there we stood, waiting for the train. He offered me a peppermint from a
small metal tin. Of course my parents taught me to never take sweets from
strangers, so I instinctively declined even though I'd now left home and
thought of my self as a grown-up.

Anyway, we got talking. At first it was 'what are you studying?' kind of
polite interest. He was intrigued that I was a computer science student.

I've gotta underline again how unusual this was, for anyone in London to ever
talk to another stranger, but this really happened. I don't think I ever
acknowledged there was anyone else in London, ever. It wasn't even normal to
know the names of your neighbours.

And so we sat beside each other on an underground train and he told me about
his early years as a programmer. Did I know APL, he asked? I had never heard
of it! His veiled references suggested he worked with but not for Cheltenham.

And he delighted in telling me programmer war stories from when he did
commercial stuff like how a vendor had encrypted their APL programs and he had
reverse engineered it and waved the decrypted source-code in front of the
firm's rep and complained about shoddy code and bugs! At the time I was
tackling Simon Singh's Code Book contest so that kind of story caught my
imagination and I begun to wish I'd have that kind of chance in my programming
future.

Now, in his old age, he went from his home in the north of England down to
London once a week for a charity meeting he chaired. That's the kind of thing
respectable old gentleman do to give their life meaning, I guess.

Anyway, afterwards I searched the web for APL (this was before google) and
was, of course, gobsmacked.

~~~
smcl
For non-Brits, "Cheltenham" = GCHQ

~~~
nostrademons
For non-Brits, GCHQ = the British intelligence service, roughly equivalent to
the US NSA. (This non-Brit had to Google.)

~~~
subcosmos
My hobby :

Showing people in the bay area this photograph and asking them if they've seen
the new Apple HQ

[https://en.wikipedia.org/wiki/Government_Communications_Head...](https://en.wikipedia.org/wiki/Government_Communications_Headquarters#/media/File:Aerial_of_GCHQ,_Cheltenham,_Gloucestershire,_England_24May2017_arp.jpg)

------
Karto
A few years ago, discovering J and playing a bit with it, I went through
phases : "this looks square and clean, a nice exercise in language design" ->
"those guys take it way too seriously" -> "people seem to be using it for
serious stuff, they are simply insane".

Coming back to it every now and then for kicks slowly showed me a few
strengths. First, with the short verb names and clear semantics, J is the only
thing I've found that brings, for me, the comfort of a specialised handheld
calculator to the PC. That realization, very independently from its array
capabilities, is what got me really going with it, on a gentle learning curve.
And you get it on your smartphone too ; I eventually sold my good old HP48
friend.

From there I started using it for small things. When I was building a lift for
my brother's Warré beehives, J let me scribble a few beam-resistance equations
in it and using its solver and plotter to easily get good results. So I
started using it for things that were too big for spreadsheets, but that I was
too lazy to deal with in a "proper" language.

That needs a change of mind regarding how you write and maintain programs.
When I want J to do something in a program, I fiddle with it until I get the
"sentence" right, and that's it. That sentence will never be modified again.
If I need it to work differenty, I'll rewrite that sentence from scratch. Then
find a good name for your sentence so that you can combine it with others, and
suddently you discover that you can write J like a nice DSL that can very
satisfyingly sound like plain spoken language.

I wouldn't stretch it though. I'm not passionate enough about it to invest
what's needed for mastery. 80 lines of thin J is my largest. Beyond that,
switch to something that helps with maintainability, but beware of the sudden
and amazing code-size inflation !

~~~
pmarin
> When I want J to do something in a program, I fiddle with it until I get the
> "sentence" right, and that's it. That sentence will never be modified again.
> If I need it to work differenty, I'll rewrite that sentence from scratch.
> Then find a good name for your sentence so that you can combine it with
> others, and suddently you discover that you can write J like a nice DSL that
> can very satisfyingly sound like plain spoken language.

I had exactly the same experience with Forth. It is very cool when you define
a word as an almost English sentence and all the data flow effortlessly
through the stack but I have to admit it can take a lot of time to get it
right. I got to the conclusion that Forth is a contemplative language where
you spend a lot more time thinking than typing.

------
TimTheTinker
I once got talking with an anesthesiologist who was taking care of a family
member. Upon hearing I was a developer, he told me he was an APL programmer
who spent most of his computer time developing Bible software. He regaled me
with a few APL war stories, about how he could get so much more done with so
much less code...

I was intrigued, and still am. But one thing I didn't catch -- how do you
write all those non-ASCII symbols using a standard OS and text editor? Or does
it require special tools?

~~~
patrickg_zill
You use a font that has those symbols and then Alt key combinations to make
the characters.

~~~
TimTheTinker
Wow... How about on a Mac? Option and Shift-option keystrokes?

~~~
patrickg_zill
Yes. I have the free but non open source APLX running on my iMac and have the
image of the keyboard map they supply loaded in Preview.

Many of them are mnemonic, such as iota being (key)-I for example.

~~~
4thaccount
Free because the APLX vendor eventually decided to focus on their legacy
software business and get out of selling an APL interpreter. I think they
essentially needed a rewrite or just a lot of work on the product and couldn't
justify it. Dyalog agreed to host the old and unsupported APLX interpreter on
their site if anyone wants it.

------
nabla9
APL and Prolog/Datalog are local optimums in programming languages. When you
enter their domains, you are limping in every other language. It's almost
better not to know about them because you can avoid constant "there is a
better way" in the back of your head.

I think we should just bite the bullet and make them into standard domain
specific languages available in every language and environment.

~~~
jeffreyrogers
What domains are they used in? I've learned a little bit of J but got put off
because most people involved with J seem more interested in using J for the
sake of using it rather than actually doing anything substantive with it. My
impression is that APL is similar (at least currently) but I'd love to be
wrong.

~~~
Jtsummers
I got into J in the '00s, it was interesting. The community was making
substantive stuff, but they were making it for themselves more than for anyone
else. I noticed a _lot_ of teachers in the mailing lists. They were making
tools that helped them track grades and attendance. They were generating
quizes and worksheets from question banks that they produced over the years.
They were creating puzzles for their students. All of this was substantive,
but it was focused on their ability.

J (and APL) really seemed to be an extension of what computing could've been.
As a computer scientist and programmer, any language and OS work _for_ me. I
want something, I make it. I can write an app in C or C++ or Java or Lisp or
Erlang or... because I have the background for all of that. For most other
users, they have to find a program that accomplishes their need, or maybe they
do it in Excel or Google Sheets. But in the past we had an idea of interactive
languages that were the main interface for the user. The user could then
produce the things they needed to meet _their_ needs. They didn't need me, the
CS guy, they could produce at least a functional prototype that met the need
for the day. Then over the years they'd tweak it, add more, grow it into
something comprehensive, or it reached a natural limit (due to complexity or
meeting requirements).

J and APL are from that branch of computing. We've hidden it in our OSes (to
varying degrees), encouraging people to buy programs that accomplish X rather
than providing them an environment to produce their own programs to do X. The
APL family of languages makes it front-and-center about the user accomplishing
their needed computations and activities.

~~~
saulrh
I think that we actually already have something much like the alternate world
you describe - linux distros.

The posix shell language is _amazing_ at what it does. There is no language in
existence in which it is as easy to fork and exec two programs with different
collections of arguments and connect their standard streams together. In fact,
it's so easy to do those things that these languages have been universally
adopted, bare and raw, as both the first and last user interface that experts
reach for when operating a computer. I log in to a posix shell, I use it to
find files and launch programs and deploy software and talk to people, and I
depend on it when civilization has fallen and I need to re-establish operation
using only what I can scavenge in the howling emptiness of my bootloader's
recovery console.

At the same time, these shell languages are in many ways objectively terrible.
They're practically made of subtle unexpected behaviors, their provisions for
modularity are terrifying, and they're so deeply baked into so many things
that they're past ossified and well on their way to fossilization. Google's
style guide for bash [1] draws the line at 100 lines of code - if you have
that much logic you _need_ to switch to a better-suited language _now_.

But there are situations where people couldn't follow that rule. As pointed
out by the Oil Shell project [2], most linux distros are almost entirely sh
codebases. And I think that these give us a good view into the kind of
alternate world you're looking at. They grew that way because they are the
result of hundreds or thousands of people over the course of decades using the
language as their main interface, building functional prototypes interactively
and then tweaking and packaging and adding functionality until they became
comprehensive or capped out. And then people adopted those tools and they
became part of the operating system. I guarantee you that /etc/rc can trace
its origins back to some angry sysadmin deciding that this whole "booting the
operating system" thing was too much work and needed to be automated.

Personally, I think that there's a reason we went the direction we did. In
some ways, languages like APL and sh are neat. I _can_ , in fact, use bash as
a core interface for sysadmin tasks. But at the same time, I've seen some
pretty horrifying code in my time as a programmer, and I find shell scripts in
/etc/ that near the top of the list. These hyper-expressive interactive
languages are fantastic for their purposes at the cost of their performance in
other domains. It might take me an hour to get twenty lines of bash working
safely and reliably, and every moment of it I'm thinking to myself, "there's a
better way to do this, I should just use $other_lang".

1:
[https://google.github.io/styleguide/shell.xml?showone=When_t...](https://google.github.io/styleguide/shell.xml?showone=When_to_use_Shell#When_to_use_Shell)
2:
[http://www.oilshell.org/blog/2018/01/15.html](http://www.oilshell.org/blog/2018/01/15.html)

------
upofadown
When I was in engineering school an APL programmer friend came over to where I
was working and looked at my MATLAB homework. She eventually stated that
MATLAB was a very bad APL. She then proceeded to solve my homework in a single
line of MATLAB.

~~~
GlenTheMachine
MATLAB doesn't deserve the moniker of a "bad APL". It's a bad FORTRAN.

------
breenhead
For anyone interested in apl, take a look at k which is essentially apl
restricted to the ascii character set. There's also q (aka kdb) which adds
some additional database-like functionality (among other things) however it's
proprietary and "free".

~~~
curiousgal
Last time I searched for Kdb I found that it's highly used in finance, is that
still the case?

~~~
breenhead
Speaking as a kdb programmer in finance (although for an unusual use case),
most big (and some small) banks have an Enterprise license and have one or
more teams that maintain a market data store and/or an order
reporting/reconciliation/PNL stack.

There are a decent number of hedge funds that use it for more or less the same
purpose but work with other data sets in addition to market data

For storing and exposing market data, you need very little additional code.
Maintenance is a different story.

~~~
neonate
What's the unusual use case?

~~~
breenhead
Doing analytics on streaming packet capture data. Probably not as unusual as
the red bull f1 racing team using it for wind tunnel analytics.

------
Jtsummers
[https://www.dyalog.com/uploads/documents/MasteringDyalogAPL....](https://www.dyalog.com/uploads/documents/MasteringDyalogAPL.pdf)

I knew the text felt familiar, the same author wrote the above linked book.
The intro covers the same material. If you're interested in APL (NB: Not a
professional, just liked playing with it), that book was really useful to me
last year.

------
macleginn
“This example shows clearly that there are ways of reasoning other than those
which have dominated information processing for 40 years but they are, alas,
still extremely rare. This difference and originality, introduced by APL, are
major features. They typify the open and welcoming intellectual spirit of the
people who practise it.” — FWIW, this example (+/ Salaries ×
Rates[Categories]) can be rewritten nearly word for word in R
(Sum(Salaries*Rates[Categories])), so at least some of the ideas still have
some currency.

~~~
mruts
I would say that pandas and R can pretty much express everything that APL/J/Q
can. They are a lot slower though (than Q atleast, I haven’t used J or APL)

~~~
beagle3
Basic operations, yes. Composabilitu, not quite.

I don’t remember enough APL, so my examples are K:

Maximum subarray sum: |/(0|+)\

Flatten: ,//

Rank: <<

In these examples, every single character is its own operation, and they
compose to give another useful operation.

Any Turing complete language can express what any other Turing complete
language can (by definition). And pandas/r do provide APL’s vector and matrix
operations. But not the composability, which IMHO is just as important to what
this family brings to the table.

~~~
mruts
Well every pandas operation returns a DataFrame so that’s pretty composable.

No doubt APL-likes are much nicer than pandas but in terms of operations, I
belive they support the same operations.

~~~
geocar
, is a function, not dissimilar to pd.concat and indeed, x,y is very similar
to pd.concat([x,y])

/ is an operator. It's similar to functools.reduce.

,/ is a function, not dissimilar to pd.concat, ,/x is pd.concat(x) which is a
little weird. It's tricky, but not impossible to implement
functools.reduce(lambda x,y: pd.concat([y,x]), x) but I might've gotten the
order of the arguments wrong.

,// is also a function. I think you can do pd.concat(x).values.flatten(), but
this obviously doesn't compose. I don't see how you can implement it with
another functools.reduce but maybe functools.reduce operates on dataframes
after all, so maybe it's just functools.reduce(lambda x,y:
pd.concat([y,x.values.flatten()]), functools.reduce(lambda x,y:
pd.concat([y,x]), x)) but I have no idea: pd.concat(x).values.flatten() is
shorter so I can't imagine anyone would prefer trying to make this monstrosity
work.

Being "much nicer" is everything. If the syntax, and the rules for the
syntactic elements means nothing, and you are fine with _merely_ the ability
to write the transformations, then you haven't thought about this clearly: VB6
is the same as Pandas since it too supports the same operations (or they can
be implemented, as they can be in any turing-complete, and many non-turing-
complete languages), but I find this line of thinking quite insulting: Pandas
is _much_ better for data programming than VB6, and whether you know it (or
like it) or not, APL and their ilk are _much_ better than Pandas for data
programming.

~~~
beagle3
The second / is converge, rather than reduce - I don’t think python (or
pandas) has it in a common library - and even if it did, usage would be ultra
clunky. Your description is excellent, just wanted to make it more precise.

------
michaelbuckbee
I'm never quite sure what to make of APL. It feels fantastically advanced for
its time. Hardware keyboards? Performance?

~~~
3chelon
When I was a graduate dev I worked for a company whose primary product was a
APL interpreter. So it was an interpreted language, but it may well be
possible that it can be compiled or JIT these days. The interpreter was
written in 68K assembler and was pretty fast I suppose, but then I'm not aware
any benchmarks to compare it with, since APL is not like anything else
(except, as someone pointed out, maybe MatLab).

------
rakoo
It seems to me APL and family are mostly useful for numerical work on data
that is possibly queried (efficiently at that) from a database. A very naïve
way would be to say it's a glorified Excel. Is there something I'm missing ?
Are there other domains one could use it for ?

~~~
BoiledCabbage
There was an _extremely_ impressive video a year or two back of someone who
had built a compiler in APL. While I don't code in it, it changed my view of
APL and its power.

HN was fairly caught up with it for a month or so, and a flood of APL posts.

Someone may have a link to it.

~~~
4thaccount
Just look for Aaron Hsu Co-Dfns on GitHub, talks on YouTube, and on HN...I
think his username here is arcfide. Look for his submissions. He's probably
100x better at coding than me and never leaves notepad.

------
paperwork
Those who have experience with array languages, is it fair to say that
something like numpy captures most of the benefits of APL/K?

If Python allowed a reduce operator “/“, numpy will be able to get even closer
to APL, correct?

~~~
icen
In terms of semantics, sure. However a real part of the charm of APL (and J,
and K) are in the syntax, and how notating your program causes you to think
about it differently. Something like or/and outer product in the game-of-life
oneliner is very straightforward APL, but is much clunkier to write in numpy.

~~~
improbable22
I just found that there's a Julia package for at least some APL syntax,
perhaps an easy way to play. [3] is a fork updated for v1.0:

[1]
[https://www.youtube.com/watch?v=XVv1GipR5yU](https://www.youtube.com/watch?v=XVv1GipR5yU)
[2]
[https://nbviewer.jupyter.org/gist/shashi/9ad9de91d1aa12f006c...](https://nbviewer.jupyter.org/gist/shashi/9ad9de91d1aa12f006c4)

[3]
[https://github.com/MasonProtter/APL.jl](https://github.com/MasonProtter/APL.jl)

------
robomartin
As someone who actually used APL prifessionally for a decade I am always
surprised by how often the language surfaces on HN. I used it in a wide range
of domains, from business and engineering applications to DNA sequencing.

The main comment I want to make is that anything that abandons notation is an
abomination. The power of APL comes from the use if notation as a tool for
thought and the expression if ideas. Notation is crucially important in this
regard. Language transliterations like J were huge mistakes in APL’s
historical timeline.

------
ColanR
I still see two things missing from currently available APL dialects: being
able to compile programs, and being able to create a control loop (which is
required for continuous access to data input).

I wonder how much effort would be required to use, say, GNU APL for compiling
the language?

------
dang
From 2014:
[https://news.ycombinator.com/item?id=7813204](https://news.ycombinator.com/item?id=7813204)

------
rbanffy
In college I learned APL. Most of my colleagues complained that we were
learning it instead of something with more practical use or market value.

APL taught me it was possible (and remarkably easy) to write "write-only" code
and how delicate legibility can be. Most of my APL code had 4 lines of
comments for each line of code.

~~~
renox
When I learned APL (which I never used) that when there was a bug, it was
faster to rewrite the whole line using a different way than to debug the line.

A truly 'write only' language..

It shows in the article: the 'min' operation works both with an array and a
scalar. Nice when you mean it, not so nice when you don't.

------
benji-york
Every time APL comes up, I — as a non-APL programmer — am compelled to post
this fun video about implementing Conway's Game of Life in APL:
[https://www.youtube.com/watch?v=a9xAKttWgP4](https://www.youtube.com/watch?v=a9xAKttWgP4)

------
csomar
Quoting from the article:

>> To get a similar result by means of a traditional computer language
requires many instructions, which hides the object of the calculation behind
arcane programming. Here, for example, is what one would write in PASCAL

It seems that the article emphasises on how APL can get a lot done with little
code. I know of a programming language that can help you do that: Rust.

Rust has two powerful features:

1- Traits: You basically declare a "struct" type that has your data. Implement
the Mul/Add Traits to it; and then "boom" you can multiply these seemingly
complicated objects with *.

2- Macros: You can abstract repetitive code with macros. For example your code
displays a table on the terminal. You have to do that repetitively. You can
either create a function to display your data or have a macro do it.

------
joelthelion
Is there a good open-source APL-like language somewhere?

~~~
icen
GNU APL is a perfectly reasonable APL implementation.

There are open source implementations of some K versions - Kona, which is K3,
and oK, which is ~K5.

J is available under GPL3.

------
tempodox
So, is there a Machine Learning Docker with APL pre-installed?

