The Array Cast is creating a series of podcasts (with transcripts) on array programming languages, which they consider to be APL, J, k, and q. Their latest episode, Loops and Learning about Array Languages, indirectly points to a strength of modern Fortran, which has array operations and which also executes loops fast. Once LFortran is mature (the cited languages have REPLs), I think discussions of array programming languages will have even less reason to ignore Fortran.
I’ve been a big fan of APL since the 70’s, but it took me a very long time to realize that it’s because it is such a wonderful environment for functional programming, whose core idea (IMO) is composability, and in APL an array can often be viewed as a function whose domain is a (tuple of) integer arrays.
Fortran missed some bets when it raided APL for ideas in the 80’s. You can’t have more than one part-ref with rank in the same designator, you can’t have a subscript with rank > 1, MATMUL is restricted to matrices & vectors, TRANSPOSE is only for matrices, &c. And some people think that explicit DO loops are just more readable than array operations.
One could define a
.x. operator in Fortran such that
A .x. B is equivalent to
matmul(A,B) for matrices and vectors. What should it do for arrays of dimension 3 and higher? For array dimensions higher than 2, should
transpose in Fortran emulate numpy.transpose?
I don’t understand the “part-ref” comment.
IBM got a European patent for a translator from APL to Fortran 77 in 1987 that expired in 2007. Translating to modern Fortran should be easier.
program rank_part type t real :: x(3) = 0.0 end type t Type(t):: z(2) z = t(x=[1.,2.,3.]) print *,size(z) print *,size(z(1)%x) print *,z%x !error end program
Coincidentally, there is a very active Twitter thread on arrays (in Fortran) with 1k likes and more than 50 comments:
Some of my favorite posts:
By Pontus Bergsten:
I work in a huge c++ code base, which have a dependency to an f2c:ed version of Lapack (amongst others). It is fun to watch the hyper light speed compilation of the lapack files, compared to the c++ files (especially those wich are template heavy with boost dependencies.
I still find it astonishing that C or even c++ never supported a native matrix type. It’s a trivial thing to do. The lack of a native type invites 10,000,000 different and incompatible homebrew solutions.
In the mid-seventies at Swarthmore College, we were mired in punched card Fortran programming on a single IBM 1130. The horror, a machine less powerful than the first Apple II. My job six hours a week was to reboot after each crash. People waited hours for their turn to crash the machine. I let a line form once people had their printouts. I’d find the single pair of brackets in a ten line listing, and I’d explain how their index was out of bounds.