Re: E123 when referring to function argument

2023-05-23 Thread Matan Nassau

> On May 23, 2023, at 09:48, Bram Moolenaar  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

-- 
-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_use+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/9369FB6A-13DC-463D-9717-6C53D94B1914%40gmail.com.


Re: E123 when referring to function argument

2023-05-23 Thread Bram Moolenaar


> I want to peek into a lambda so I can evaluate it in a new Vim process. Why
> do I get 'E123: Undefined function: Op' when I source this script?
> 
> vim9script
> def! g:LambdaText(Op: func(): number): void
> func Op
> enddef
> 
> def! g:TestRun(): void
> g:LambdaText(() => 2 * 4)
> enddef
> 
> g:TestRun()

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


-- 
Be thankful to be in a traffic jam, because it means you own a car.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///  \\\
\\\sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_use+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/20230523134823.1939E1C0F38%40moolenaar.net.


E123 when referring to function argument

2023-05-22 Thread Matan Nassau
Hello.

I want to peek into a lambda so I can evaluate it in a new Vim process. Why
do I get 'E123: Undefined function: Op' when I source this script?

vim9script
def! g:LambdaText(Op: func(): number): void
func Op
enddef

def! g:TestRun(): void
g:LambdaText(() => 2 * 4)
enddef

g:TestRun()


Matan

-- 
-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_use+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/CAATngTObX3maQ32K6TFSRmSsLuY9D0S2m2Ob-fYGYwuPsobQ9A%40mail.gmail.com.