Array programming is serious fun. I’m not much of a programmer, in fact I’ve hated it most of my life (at least ‘til my 40s). But array programming paradigm is something different. It’s one of those things that you discover, where all the cool kids are. It’s a scene of its own.
While traditional programming considers itself with memory slots and variables pointing to those slots, array programming is something different. Array programming treats arrays as the fundamental data item. Originally it was developed as a math notation by Kenneth Iverson in the 1950s. After Iverson published his book A Programming Language, the name APL was coined.
APL was used from the beginning in describing algorithms. Consider the following example from Iverson’s aforementioned book:
The diagram illustrates a complete flow of an algorithmic program computing matrix multiplication. A program begins at a point indicated by an entry arrow, and ends at a point indicated by an exit arrow.
Iverson provides the following description for the program: “Steps 1-3 initialize the indices, and the loop 5-7 continues to add successive products to the partial sum until & reaches zero. When this occurs, the process continues through step 8 to decrement j and to repeat the entire summation for the new value of j, providing that it is not zero. If j is zero, the branch to step 10 decrements j and the entire process over j and & is repeated from j = v(B), providing that j is not zero. If j is zero, the process is complete, as indicated by the exit arrow.”
APL has since significantly moved forward, but the core conventions and algorithmic thinking is what sets apart array programming from procedural programming.
I’m especially fond of the newer languages that APL has spawned. One of them is called Kap by Elias Mårtensson. It provides an APL-like syntax with a programming environment running in the JVM. And it’s being constantly developed. And in some ways it’s a newcomer friendly. Consider the following example:
def print_hi(name)
puts "Hi, #{name}"
end
print_hi('Tom')
#=> prints 'Hi, Tom' to STDOUT.
written in Kap:
∇ print_hi (name) {
io:println "Hi, ",⍕name
}
print_hi "Tom"
⍝=> prints 'Hi, Tom' to STDOUT.
Easy, isn’t it?