Tuesday, May 23, 2023

Re: E123 when referring to function argument


On May 23, 2023, at 09:48, Bram Moolenaar <Bram@moolenaar.net> wrote:

The argument of the "func" command is a function name, not an
expression.  You are passing a variable, which is an expression.

There is a trick you can use: Assign the function reference to a global
variable.  Function names exist in the global namespace where the global
variable can also be found:

    def g:LambdaText(Op: func(): number): void
        g:ThatFunction = Op
        func g:ThatFunction
        unlet g:ThatFunction
    enddef

Thank you, this clarifies things.

I also learned I can call string(function(Op)) to get the lambda's name, and then call execute('func ' .. lambda_name) to get the lambda's body.


Matan

No comments: