

Lessons from APL, a “lost” languageA few weeks back the forum that I go on often held a obfuscation challenge, and people joked around about submitting a entry that was coded in APL. APL (A Programming Language) is a programming language that was developed at IBM by mathematician Kenneth Iverson. It is mainly infamous because of its need to have a separate keyboard installed to code in it: The challenge involved making a simple program:
One of the bigger issues with writing this blog post is that most browsers can’t even display a lot of the symbols I need to demo. Above is what I submitted, and I think its a great idea to go though on what the program and give a small demo on how powerful APL really is. It’s first worth noting, I used GNU APL. Since most APL interpreters where designed way before i386 was around (Or if they where, for MSDOS), there is not a great deal of choise.
One of the first things I really got quite annoyed by is the large amount of flags needed to make it function as a “normal” language. Overall though I though it was a nice language, My explanation to the large amount of symbols are below: So there are 5 major vars, I l T E X and K The first three parts are the fairly simple parts of the code: Hiding the strings
So here we are seeing The This is done by running In that order when you run Moving onFirst we start off a new function by asking
When
2,3,5,7 is prime. Expanding this more we can notice Or in a more easy to read fashion: This does a check to see if any of them match what put in I.
As can see all of the older vars have been turned into 0’s apart from the 7 that we put in, that was turned into 1. Next we take the output as an array and try and get a element from it.
As you can note. We have used the same function twice. So I will remove that to make it clear.
The
The last part is
The We can now simply put this as To print Prime or not to.To pick if we should print We have already gone through what T[E⌈X] does.
the
In this, the amount to chop off the front is dependent on what We can simply this to If it is 1 then that is multiplied by 4 and thus becomes 4.
or if it isn’t because it is a multiplication by 1 it becomes:
Then we end the function using All of that function was stored in It’s worth noting that there isn’t an exit issue, this is because But wait you didn’t explain the huge long function. Well now that you have asked…Note, I have made the var names easier to distinguish going down Before in this we simplified the long line into a basic component:
First we are going to remove the number fill ins, Like the ones I did last time.
Now we have a zero and two in the mix. We know that This function works by assuming that is number A is multiple of another number (B) then the remainder of A divided by B is zero. The function
We can do this on an array/vector of numbers. So a better way to explain this function is:
Then we can use
If this does not make sense (don’t worry it made no sense to me) I would annotate it like this:
So we can use this trick to look for primes now:
Here we now have a bunch of remainders. Because we only care about 0 and 1 remainders in this case, I will be adding
Now adding
(Observe that the first number is 1 because all but one row is 1 in that col). Now we can finally spot what we are looking for. We are only looking for where the results are 2
Then we compress the array down:
Oh look. Prime numbers! The downside of this way is that its really really slow. But then again, this wasn’t a speed showdown. 

Like the blogging engine? Click here to see the code 