Forum Discussion
Lambda Example: Generate Fibonacci series
Your description looks pretty much spot on, I guess you are coming from vba or other imperative programming background so are converting to loops. In the functional world one only needs functions and values - even arrays can be treated as functions like in the 'list' function. In your MAP equivalent one could pass a second argument of column indices {1,2} to return both columns. BYROW was used for the single column case only because it removed an extra lambda.
A key point I hadn't fully appreciated before was that wrapping LAMBDA around an expression causes re-evaluation for each function call, this can cause a big slowdown for example within SCAN. If lambda arguments are evaluated using LET in advance, performance can improve dramatically.
lori_m wrote:If lambda arguments are evaluated using LET in advance, performance can improve dramatically.
That is something I have never managed to achieve! Since the Thunks are subject to Lazy evaluation, I have always finished by re-evaluating the entire array each time I wish to access an element of the array which is very expensive computationally. Actually performing the array calculation and then gathering the result as a Lambda array would appear to offer a great route forward.
I do not appear to have got savings from my attempt to replicate your approach as yet and seem to require further guidance. The tests I have tried with the first formula are based upon 4 rows of 1000 random values, which I sort or accumulate row by row. In each case my attempt to replicate your 1st formula performs much the same as REDUCE/HSTACK rather than accumulating or sorting the 2D array as a single hit.
The second formula looks promising applied to the Fibonacci series but I have yet to extract the ideas to apply them to other problems.