2

Following from my previous question, it seems that APL performs a scanl in O(n^2) but the compiler is smart enough to optimize for simple primitives. What then is the best strategy to apply \ to non-simple functions? Additionally, there are many cases when the right associativity does affect the result, for example:

{0⌈⍺+⍵} \ 3 ¯4 1 5 ¯1 ¯2 ¯3 2 0 4           ⍝ 3 0 3 5 4 5 5 5 5 5

Which is not the answer I would have expected 3 0 1 6 5 3 0 2 2 6

mazin
  • 395
  • 2
  • 7

1 Answers1

1

I stumbled on one possible solution, but don't know if it's the most idiomatic.

s←0 ⋄ ↑{s⊢←0⌈s+⍵}¨ 3 ¯4 1 5 ¯1 ¯2 ¯3 2 0 4

Correctly gives me 3 0 1 6 5 3 0 2 2 6

mazin
  • 395
  • 2
  • 7