The BEAM needs an APL-y language

Image for post
Image for post
APL — yikes, scary innit?

One like, one unpopular opinion is one of them top Twitter games, innit?

Well this is mine — the BEAM, which already has Prolog-y (Erlang), Algol-y (Elixir) and Lisp-y (LFE) languages needs an APL-y language wut looks like the pic at the top of this post.

APL — which stands for Another Programming Language, imagine the brass neck of that, eh? — is an old 60s language designed to be expressive.

Why in the name of God and all the Saints?

Good question — lets start with why before we tuck in. The only reason to write a new programming language is to be able to do things better/faster.

Way back in the day I was hired at Basho and had to do their coding challenge. As the company is bankrupt now, lets see it:

My solution is online now — basically 500 raw lines of code in total, including tests. So what would it look like in APL? Something like this (forgive me the gods of APL, for I is a noob):

(you can’t do flow control in the in-browser REPL I wrote this in, sooooo…. This version is also probably a bit too long and real APLer could do it shorter.)

What’s yer takeaway son? What does it all mean?

The APL programme is/would be much smaller than the Erlang.

APL is designed to be so expressive that whole programmes can be written on a single page and their structure grasped by the programmer. This prezzo makes the case for APL ably and without it I wouldn’t have written this blog post. Do read it — it blew my mind.

The coding example is a key part of CRDTs (Convergent Replicated Data Types) and a swatch at one of those CS papers might give a clue as to why it is so short in APL, it all set-based maths:

Image for post
Image for post
Extract from a CRDT paper https://hal.inria.fr/inria-00555588/document

APL is designed to be expressive — and exposes many set operations to the developer — it is quick to write CRDT-like things because it is designed that way. Once you understand the seemingly bizarre syntax it is actually a very simple language.

Bear in mind my APL experience is reading the manual for 4 hours on a flight, and programming for another 4 so: 1 days experience tops.

By comparison when I did it in Erlang I had 11 years full time under my belt.

So are there other use cases?

Riak has a number of other gnarly problems which have elegant statements of requirement but whose implementations have considerable accidental complexity when written in Erlang.

Some promising places a BEAM APL-y language could help might be:

  • the claim algorithm — which handles placement of vnodes on the cluster
  • preflists — where to do to to read data from the cluster, particularly for stuff like rack-awareness and guaranteed writes to multiple data centres and stuff
  • ring resizing — how to restructure the data distribution on a cluster dynamically

What was APL used for when it was used in programming?

A core technique in APL is taking two sets of information and generating an boolean matrix with them, and then apply a set of rules to reduce that boolean matrix to a single boolean — a decision, yes/no. Essentially it is a business rules language.

My dear friend Mary Kane informs me that when she left school to join Irish Life Insurance she was trained as an APL programmer — taking sets of actuarial tables, apply an individuals data to them and reducing the resulting boolean matrices to business decisions, buy/sell, pricing, calculate returns, etc, etc.

This pattern will be familiar to spreadsheet users. Spreadsheets as a business function are largely large sets of static data which are mapped to boolean matrices in the presence of scenario data and then reduced to decisions.

The famous paper on what functions spreadsheet users actually use makes this very clear. They dumped every spreadsheet at a large company and a government department and then finger-printed function use in them. The results are stark: sum, vlookup and if for the win:

Image for post
Image for post
https://arxiv.org/abs/1111.6866

So basically turning spreadsheets into business programmes then. (A subject that some of you will know has long been close to my heart.)

Gonnae write an APL language for the BEAM then?

Jeezo, naw, Ah’m run aff ma tits.

Sometimes you are just pregnant with a whole programme — you can see its implementation suddenly, as from a blue sky, and you just need to vom it out through your fingers — so it is with this APL dialect.

But I really have too much on my plate with a new job and all to do such a thing. If anyone fancies it I could write up how I would do it ;-)

If you like this share it on social media and follow me on Twitter

Written by

Former SNP Parliamentary Candidate — Quondam Computer Boffin

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store