Vim9: Not able to define a legacy script-local function inside a def function

7 views
Skip to first unread message

Yegappan Lakshmanan

unread,
Dec 13, 2021, 10:32:58 AM12/13/21
to vim_dev
Hi,

Inside a Vim9 def function, I am not able to create a legacy
script-local function
using the "s:" prefix. Example:

----------------------------------------------------------------------------------------
vim9script

def T()
func s:F1()
endfunc
var Fn: func = s:F1
enddef
defcompile

func s:F2()
endfunc

var Fn: func = s:F2
----------------------------------------------------------------------------------------

When I source the above script, I get the "E1075: Namespace not
supported: s:F1()"
error message.

I am able to define a script-local function using the "s:' prefix at the script
level though.

- Yegappan

Yegappan Lakshmanan

unread,
Dec 13, 2021, 10:47:59 AM12/13/21
to vim_dev
The same issue applies to Vim9 def function also:

----------------------------------------------------------------------------------------
vim9script

def T()
def s:F1()
enddef
var Fn: func = s:F1
enddef
defcompile

def s:F2()
enddef
var Fn: func = s:F2
----------------------------------------------------------------------------------------

If I source the above script, I get the "E1075: Namespace not supported: s:F1()"
error message. But at the script level, there is no error.

- Yegappan

Bram Moolenaar

unread,
Dec 13, 2021, 3:39:47 PM12/13/21
to vim...@googlegroups.com, Yegappan Lakshmanan
The basic idea is that script-local functions are defined at the script
level. And not created or deleted dynamically.

The main reason is that in a compiled :def function these script
functions can be called by index, instead of having to look them up by
name (and handle failure). That is more efficient and allows for type
checking of arguments and return value.

Currently this function lookup by index only happens for :def functions,
but it could also be done for legacy functions. Applying the same rule
for both type of functions is more consistent anyway.

--
Time is an illusion. Lunchtime doubly so.
-- Ford Prefect, in Douglas Adams'
"The Hitchhiker's Guide to the Galaxy"

/// Bram Moolenaar -- Br...@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 ///
Reply all
Reply to author
Forward
0 new messages