0

Maybe I am missing something but I am getting an incorrect result on two excel Lambda functions in a simple test.

One is named xytest():

=LAMBDA(x,y,
 IF(x > y,
  addy(x,y),
  "x=" & x & " < y=" & y)
 )

the other is addy():

=LAMBDA(x,y,
  xytest(x,(y+1))
 )

It should just be recursive until y is greater than x. But when I put in =xytest(8,4) I get the following result:

x=8 < y=8

I don't know how this is happening because there is no incremental testing, but I wonder if the IF(x > y) is actually preforming x is greater than or equal to? It should obviously iterate until y=9. I am either seriously confused about how Lambda() works or there is an error in my formulas. Unfortunately, I can't find much technical documentation on Lambda() to try and sort out what's going on.

SmithL
  • 23
  • 8
  • 6
    "It should obviously iterate until y=9" -- well, no. The mutual calls continue until it is no longer true that `x > y`, which happens when `x <= y`, which happens when `x = y = 8`. Barring decent debugging support (they might still be working on that :P) just write out the calls yourself. – Jeroen Mostert Feb 25 '22 at 20:15
  • I got it. Thanks. I was using my excel formula brain instead of my coding brain. You are 100% correct. "X is greater than Y until they are equal". – SmithL Feb 25 '22 at 20:26
  • 2
    @JeroenMostert Agreed re debugging - we can dream of an updated Evaluate Formula dialog box which can process recursive LAMBDAs! – Jos Woolley Feb 25 '22 at 20:27
  • I agree. It is just such a powerful tool, it's worth wading into even if it is prone to user error. The Name Manager component is pretty awful to deal with. I wish they would let you just set the refers to: to =FormulaText(A1) and at least let you enter the formula in the bigger main window. I am switching from a cell, to Notepad++, to the Name Manager and it's not a great work flow. – SmithL Feb 25 '22 at 20:31
  • 2
    I only just learned today Excel offers this feature; the fact that they illustrate how it works by demoing a fixed-point combinator, of all things, means the nerds are currently firmly in charge, and there's not going to be a user-friendly interface any time soon. You might be better off just picking up the basics of functional programming in friendlier languages like Scheme, and then translating that experience into Excel when required (literally). Excel plus `LAMBDA` is *technically* functional, in the same way pure lambda calculus is -- and you don't want to be developing in that either. :P – Jeroen Mostert Feb 25 '22 at 20:44
  • 1
    Ha ha. I am a Python man personally, but grew up on C++ and Java. For work I have to make financial models, but I can't ever use Macros. I can't always make all the calculations I would like, especially iterative ones. Lambda should solve that problem (provided the grey hairs are at least on office 365). – SmithL Feb 25 '22 at 21:03
  • 1
    @BigBen I love learning about Lambda and Let. Hopefully I don't bug everyone with the questions, because I plan on using them a lot! – SmithL Feb 25 '22 at 21:07
  • FWIW: I thought this was an interesting article with the VP of Excel. https://thenewstack.io/excel-the-functional-programming-tool-you-didnt-know-you-had/ – SmithL Feb 25 '22 at 21:33

0 Answers0