3 ms·
As I asked in another thread about APL readability few weeks ago[1], would you be surprised to learn this is valid Dyalog APL? result←findMax data max
by jodrellblank 5y ago
As I asked in another thread about APL readability few weeks ago[1], would you be surprised to learn this is valid Dyalog APL?
result←findMax data
max←0
:For i :In data
:If i>max
max←i
:EndIf
:EndFor
result←max
then
findMax 5 1 2 3 5 6 3 1
6
Writing it more neatly as findMax←⌈/ isn't mandatory anymore than `reduce(max, numbers)` is mandatory in Python.
[1] https://news.ycombinator.com/item?id=28092097 https://news.ycombinator.com/item?id=28092097
- celeduc 5y agoI'm not surprised at all. Good/bad, un/readable code can be produced in any language. Ruby fans crowed about its beauty then created incomprehensible DSLs of awkward Yoda code. But norms and values do differ between language communities, and APL is not exactly noted for a strict emphasis on readability.
- rbanffy 5y agoThe terseness of “vintage” APL is what makes it hard to read and reason about. This example highlights how a little less terse code can be much more readable. But I remember what confused me the most was trying not to use loops to sum arrays and using vector ops like +/A