# Array programming languages

**URL:** <https://fortran-lang.discourse.group/t/array-programming-languages/1373>\
**Category:** Uncategorized\
**Created:** [June 8, 2021, 10:28pm UTC](https://fortran-lang.discourse.group/t/array-programming-languages/1373 "2021-06-08T22:28:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [June 8, 2021, 10:28pm UTC](https://fortran-lang.discourse.group/t/array-programming-languages/1373/1 "2021-06-08T22:28:10Z")

</div>

The [Array Cast](https://www.arraycast.com/resources) is creating a series of podcasts (with transcripts) on array programming languages, which they consider to be [APL](https://apl.wiki/), [J](https://code.jsoftware.com/wiki/Guides/Getting_Started), [k](https://estradajke.github.io/k9-simples/), and [q](https://code.kx.com/q/learn/). Their latest episode, [Loops and Learning about Array Languages](https://www.arraycast.com/episodes/episode-01-loops-and-learning-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.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [June 9, 2021, 12:14am UTC](https://fortran-lang.discourse.group/t/array-programming-languages/1373/3 "2021-06-09T00:14:04Z")

</div>

> [@pmk](#):
>
> 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](https://numpy.org/doc/stable/reference/generated/numpy.transpose.html)?

I don’t understand the “part-ref” comment.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [June 9, 2021, 2:24am UTC](https://fortran-lang.discourse.group/t/array-programming-languages/1373/4 "2021-06-09T02:24:17Z")

</div>

IBM got a [European patent](https://patents.google.com/patent/EP0252229A2/en) for a translator from APL to Fortran 77 in 1987 that expired in 2007. Translating to modern Fortran should be easier.

---

<div class="post-metadata">

**Author:** ![themos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/themos/32/521_2.png) [@themos](https://fortran-lang.discourse.group/u/themos)\
**Post date:** [June 9, 2021, 9:24am UTC](https://fortran-lang.discourse.group/t/array-programming-languages/1373/5 "2021-06-09T09:24:56Z")

</div>

```auto
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

```

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [June 9, 2021, 9:34am UTC](https://fortran-lang.discourse.group/t/array-programming-languages/1373/6 "2021-06-09T09:34:12Z")

</div>

Coincidentally, there is a very active Twitter thread on arrays (in Fortran) with 1k likes and more than 50 comments:

[https://twitter.com/ID\_AA\_Carmack/status/1401959248507047948](https://twitter.com/ID_AA_Carmack/status/1401959248507047948)

Some of my favorite posts:

- By Pontus Bergsten:

- Andy Somogyi:

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [June 10, 2021, 8:36pm UTC](https://fortran-lang.discourse.group/t/array-programming-languages/1373/7 "2021-06-10T20:36:55Z")

</div>

> [@pmk](#):
>
> 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.

Hacker News in a thread [Try APL](https://news.ycombinator.com/item?id=27460887) has a post by [Syzygies](https://news.ycombinator.com/user?id=Syzygies)

> 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.
> 
> …

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [June 22, 2021, 2:30pm UTC](https://fortran-lang.discourse.group/t/array-programming-languages/1373/8 "2021-06-22T14:30:00Z")

</div>

There is a language called Remora that supports [rank-polymorphic programming](https://arxiv.org/abs/1912.13451) . Fortran has had some support for rank-polymorphic programming since the F90 standard, where many inttrinsic functions act either on scalars or on arrays of any rank. User-defined ELEMENTAL functions were then added, and Fortran now allows arguments to be assumed rank arrays (although you can’t do much with them without SELECT RANK). Maybe reading about Remora and reaching out to its creators could yield some ideas for enhancing Fortran.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [June 22, 2021, 5:53pm UTC](https://fortran-lang.discourse.group/t/array-programming-languages/1373/9 "2021-06-22T17:53:57Z")

</div>

Rank-polymorphic programming is related to Mathematics of Arrays (MoA) that I’ve been trying to get up to speed lately:

- [Mathematics of Array - C Compiler](https://saulshanabrook.github.io/psi-compiler/src/index.html)
