get({func}, "name"): is it behaving correctly?

12 views
Skip to first unread message

Ernie Rael

unread,
Mar 18, 2023, 12:03:48 PM3/18/23
to vim...@googlegroups.com

Doing

def T()
enddef
echo T->get('name')
echo T
finish

produces this output

<80><fd>R34_T
<SNR>34_T

Is this expected? I just saw `T->get('name') and thought I could
use it to replace a spot where I'm extracting the name from `string(T)`.

-ernie

Bram Moolenaar

unread,
Mar 18, 2023, 4:29:19 PM3/18/23
to vim...@googlegroups.com, Ernie Rael
I get:

E121: Undefined variable: T
E121: Undefined variable: T

When I prepend "vim9script" then I do get the output you mention.

The output looks OK, you get the internal name of a script-local
function. Either the byte-code version or the printable version with
<SNR>. Note that you can also get the printable version with:

echo function('T')->get('name')


--
A child of 5 could understand this. Fetch me a child of 5!

/// 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 ///

Ernie Rael

unread,
Mar 19, 2023, 10:45:26 AM3/19/23
to vim...@googlegroups.com
On 23/03/18 1:29 PM, Bram Moolenaar wrote:
> Ernie Rael wrote:
>
>> Doing
>>
>> def T()
>> enddef
>> echo T->get('name')
>> echo T
>> finish
>>
>> produces this output
>>
>> <80><fd>R34_T
>> <SNR>34_T
>>
>> Is this expected? I just saw `T->get('name') and thought I could
>> use it to replace a spot where I'm extracting the name from `string(T)`.
> I get:
>
> E121: Undefined variable: T
> E121: Undefined variable: T
>
> When I prepend "vim9script" then I do get the output you mention.
>
> The output looks OK, you get the internal name of a script-local
> function. Either the byte-code version or the printable version with
> <SNR>. Note that you can also get the printable version with:
>
> echo function('T')->get('name')

Thanks. Now I get it; it's magic. (easier for me to understand than delving
into byte-code version and what I'd do with it.)

Never having learned vimscript, seems there are some things I'm not
easily getting a feel for, since with vim9script...

-ernie

>

Bram Moolenaar

unread,
Mar 19, 2023, 1:49:15 PM3/19/23
to vim...@googlegroups.com, Ernie Rael
See ":help get()" and go down a few lines.

--
If I tell you "you have a beautiful body", would you hold it against me?
Reply all
Reply to author
Forward
0 new messages