Forum Discussion

Tie CHENG's avatar
Tie CHENG
Brass Contributor
Aug 02, 2021
Solved

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

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?

  • 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.

     

5 Replies

  • GabrielDiniz's avatar
    GabrielDiniz
    Copper Contributor

    Tie CHENG You can actually do it just like you wanted, you just have to type the result directly, this means that:

     

    =LAMBDA(4)() does return 4, and if you attach a parameter to it, it returns #VALUE

  • SergeiBaklan's avatar
    SergeiBaklan
    Diamond Contributor

    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.

  • 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.

     

Resources