I am wondering whether I should heavily use the each operator when using APL or should I try to find another solution to a given problem?
How is usage of this operator optimized in APL?
I am wondering whether I should heavily use the each operator when using APL or should I try to find another solution to a given problem?
How is usage of this operator optimized in APL?
Instead of writing something like
1 +" 2 x" 3|" (1 2 3) (4 5 6) // sorry, no apl chars
I would write
{1 + 2 x 3 | omega}" (1 2 3) (4 5 6)
or
foo" (1 2 3) (4 5 6)
where foo contains the computation.
In other words, avoid chaining successive each operations when the functions can be combined. Dyalog DFNs {...} provide a great way to accomplish this.
But most of all, I would first try to solve the problem in the most natural way possible, without thinking about whether there is a workaround which happens to run faster. If the solution is good enough, that is, it performs adequately and you and your colleagues would be able to understand it some time in the future, I would leave it alone.
In most cases, each will not have as good performance as an array-solution that does not use each, but sometimes it is the easiest and clearest way to code a complex expression. But if there are two ways to do the task of roughly equal clarity and complexity, and one does not use each, I would tend to choose that one. If it matters, of course, instrument and measure. Unless this is working with quite large data, it will quite likely not matter. The comment above on each used with calls to long running operations or external services is accurate.