Forum Discussion
FIFO Inventory Formula Challenge
Agree discussions around simplicity / complexity, etc. are pretty pointless given their subjective (and recursive!) nature. I was thinking of 'Nice' in a 'Pythonic' sense and it does seem Excel is heading in the direction of such languages.
I don't have access to LAMBDA to test but it should be possible to use recursion within a LET statement by doing something along the lines of this Python code:
Y = lambda f: (lambda x: x(x))(lambda y: f(lambda *args: y(y)(*args)))
fib = lambda f: lambda n: (n if n<2 else f(n-1)+f(n-2))
>>> list(map(Y(fib),range(10)))
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
I wouldn't say that I have reached the point of being able to read the concise syntax that seems to be favoured in the world of functional analysis with any degree of fluency! Even in the world of imperative computing I always preferred verbose to concise (Visual Basic to Java). The Y combinator still leaves me struggling to read what is the function definition and what arguments are being processed. With conventional math, which is somewhat concise, I instinctively feed in phases such as 'with respect to' but it has yet to happen with Curry's notation.
Despite that, I seem to have written a recursive Lambda function that I have applied to Twifoo 's challenge problem and then reapplied it to a simpler problem (that of calculating a 1D column that represents row totals of a 2D array) without change.
It might be that FOREACH implements the Y combinator and XSTACK the MAP function but, right now, I lack the clarity of thought to be sure. For the sake of completeness, my function to sum rows was
= LAMBDA(arr,num,
SUM(INDEX(array,num,0))
)Not totally awe inspiring, but useful.
- PeterBartholomew1Feb 12, 2021Silver Contributor
I forgot to say, the function call was
= FOREACH(ROWS(array), SUM1ROW, array)
The first parameter would appear to be superfluous but the variable it initialises served as a counter in order to terminate the recursion.
BTW the formula you wrote for Currying the flow within the accumulation works (I assumed you had been in a position to test it). Whether it serves the intended purpose of reducing memory demands or parameter count, I have yet to determine.