SOLVED

Is it possible to define a function with no argument by LAMBDA?

%3CLINGO-SUB%20id%3D%22lingo-sub-2597503%22%20slang%3D%22en-US%22%3EIs%20it%20possible%20to%20define%20a%20function%20with%20no%20argument%20by%20LAMBDA%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2597503%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20Excel%2C%20we%20have%20functions%20with%20no%20argument%20such%20as%20PI()%2C%20RAND()%2C%20NOW().%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%2C%20it%20seems%20that%20we%20cannot%20define%20such%20a%20function%20by%20LAMBDA.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20in%20a%20cell%20%60%3DLAMBDA(%2C4)()%60%20(and%20expected%204%20as%20return%20value)%2C%20it%20raised%20a%20warning%20%22You've%20entered%20too%20few%20arguments%20for%20this%20function%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhy%20cannot%20we%20define%20a%20function%20with%20no%20argument%20by%20LAMBDA%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2597503%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2597825%22%20slang%3D%22en-US%22%3ERe%3A%20Is%20it%20possible%20to%20define%20a%20function%20with%20no%20argument%20by%20LAMBDA%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2597825%22%20slang%3D%22en-US%22%3EGood%20to%20know...%20Thank%20you...%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2597811%22%20slang%3D%22en-US%22%3ERe%3A%20Is%20it%20possible%20to%20define%20a%20function%20with%20no%20argument%20by%20LAMBDA%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2597811%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F113332%22%20target%3D%22_blank%22%3E%40Tie%20CHENG%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWith%20latest%20lambdas%20edition%20your%20sample%20could%20be%20like%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3DLAMBDA(%5Bx%5D%2C4)()%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3Ewhich%20returns%204.%20You%20have%20no%20arguments%20but%20have%20optional%20parameter.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2597736%22%20slang%3D%22en-US%22%3ERe%3A%20Is%20it%20possible%20to%20define%20a%20function%20with%20no%20argument%20by%20LAMBDA%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2597736%22%20slang%3D%22en-US%22%3EIndeed%2C%20it%20is%20possible%2C%20thank%20you.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2597553%22%20slang%3D%22en-US%22%3ERe%3A%20Is%20it%20possible%20to%20define%20a%20function%20with%20no%20argument%20by%20LAMBDA%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2597553%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F113332%22%20target%3D%22_blank%22%3E%40Tie%20CHENG%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYes%2C%20it%20seems%20to%20be%20possible.%26nbsp%3B%20e.g.%20given%20a%20named%20reference%20'x'%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3DLAMBDA(x%2B1)()%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Ereturns%20x%2B1.%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3DLAMBDA(x%2B1)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Ereturns%20a%20%23CALC!%20error.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20name%20the%20Lambda%20function%20%3CSTRONG%3EINCx%3C%2FSTRONG%3E%20then%20the%20same%20results%20are%20obtained%20for%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3DINCx()%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Eand%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3DINCx%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Erespectively.%26nbsp%3B%20I%20think%20I%20have%20read%20of%20such%20functions%20being%20referred%20to%20as%20'thunks'%20and%20would%20be%20used%20to%20pass%20a%20resource-intensive%20operation%20as%20a%20parameter%20without%20evaluating%20it%20before%20the%20result%20is%20needed.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20possibility%20of%20defining%20and%20testing%20for%20an%20optional%20parameter%20is%20being%20rolled%20out.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

In Excel, we have functions with no argument such as PI(), RAND(), NOW().

 

However, it seems that we cannot define such a function by LAMBDA.

 

I tried in a cell `=LAMBDA(,4)()` (and expected 4 as return value), it raised a warning "You've entered too few arguments for this function".

 

Why cannot we define a function with no argument by LAMBDA?

4 Replies
best response confirmed by Tie CHENG (Occasional Contributor)
Solution

@Tie CHENG 

Yes, it seems to be possible.  e.g. given a named reference 'x'

=LAMBDA(x+1)()

returns x+1.

=LAMBDA(x+1)

returns a #CALC! error.

 

If you name the Lambda function INCx then the same results are obtained for

=INCx()

and

=INCx

respectively.  I think I have read of such functions being referred to as 'thunks' and would be used to pass a resource-intensive operation as a parameter without evaluating it before the result is needed.

 

The possibility of defining and testing for an optional parameter is being rolled out.

 

Indeed, it is possible, thank you.

@Tie CHENG 

With latest lambdas edition your sample could be like

=LAMBDA([x],4)()

which returns 4. You have no arguments but have optional parameter.

Good to know... Thank you...