Forum Discussion
JackTradeOne
Mar 16, 2021Copper Contributor
Default values for LAMBDA parameters?
Is it possible to somehow include default values for LAMBDA functions with multiple parameters? For example, if my function is =LAMBDA(
height,
width,
height * width
); I would like to be able hav...
- Mar 16, 2021
If only as
=LAMBDA(height,width, IF(height, height,2)* width )(,4)
Lambda allows optional parameters if you have more than one of them. Missed parameters are returned as zero.
JackTradeOne
Mar 16, 2021Copper Contributor
I'm not sure I understand your concept of "partially apply". The desired end result is a function (say, "Area") which I can call once as Area(,4) and get "8" in return. Does you approach achieve that?
tboulden
Mar 16, 2021Iron Contributor
Apologies, partial application is a concept from functional programming which LAMBDAs lend themselves to. Not to go to far afield, you can google it if you like.
So we have Area defined as above in Name Manager; let's define Area2:=Area(2). Now when you do Area2(4), you'll get 8. If you needed to hardcode some other value, say 4, you could define Area4:=Area(4), and Area4(2)=8.
So we have Area defined as above in Name Manager; let's define Area2:=Area(2). Now when you do Area2(4), you'll get 8. If you needed to hardcode some other value, say 4, you could define Area4:=Area(4), and Area4(2)=8.
- JackTradeOneMar 17, 2021Copper Contributor
First, thanks for the explanation of partial application. Now that you describe it, I remember running into this concept before, though under a different name. I will definitely revisit that.
In terms of the specific answer - IIUC, I would need to define, in addition to your Area2, another Area function to handle situations where both parameters are present, correct? What I'm trying to achieve is one function which can accept either Area(2,4) or Area(?,4) and, in either case, return 8.
- tbouldenMar 17, 2021Iron ContributorSergei's suggestion will serve you well for those specifications then, I was proffering the suggestion in case your use case might be more open-ended.
- JackTradeOneMar 17, 2021Copper ContributorGot it! Thanks again.