Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 708629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:24:45+00:00 2026-05-14T04:24:45+00:00

I’m hoping to call a static dictionary function using call(). By static I mean

  • 0

I’m hoping to call a “static” dictionary function using call(). By “static” I mean that the keyword ‘dict’ is not used in the function’s definition. I use this nomenclature in the hopes that the effect of this keyword is to declare a static member function as is possible in java/C++/etc, ie to put the function name in the class namespace but allow it to be called without referencing an object.

However this doesn’t seem to work. For example:

" Setup:
let testdict = { }
funct! testdict.funct() 
  echo "called" 
endfunct

" Tests:
"   Following each line is an indented comment
"     containing its output in message land, ie what was echoed.
call testdict.funct()
  " called
echo testdict.funct
  " 667
echo string(testdict.funct)
  " function('667')
echo function('667')
  " E475: Invalid argument: 667
echo function('testdict.funct')
  " testdict.funct
call call(testdict.funct, [ ])
  " E725: Calling dict function without Dictionary: 667

" Same deal if there's an intermediate variable involved.
let TestdictDotFunct = testdict.funct
echo TestdictDotFunct
  " 667
echo string(TestdictDotFunct)
  " function('667')
call TestdictDotFunct()
  " E725: Calling dict function without Dictionary: 667

From the help topic E725:

It is also possible to add a function without the “dict” attribute as a
Funcref to a Dictionary, but the “self” variable is not available then.

So logic would seem to indicate that if “self” is not available, then it should be possible to call the function referenced by the Funcref without a Dictionary. However this doesn’t seem to be the case. Am I missing something?

Vim version info:

$ aptitude show vim-gnome
Package: vim-gnome
State: installed
Automatically installed: no
Version: 2:7.2.245-2ubuntu2

Edit:

What I really want to do is to allow dictionary functions to make calls to either other dictionary functions or to non-dictionary functions transparently.

This is possible by passing self as the third parameter in the call() invocation (thanks @ZyX); this parameter is just ignored if a non-dictionary function is being called. I found this kind of surprising because it’s very different from how object-oriented constructs in other languages work. But I guess vimscript’s OOP stuff is more like C than C++ in a lot of ways.

EG

let dict = { }
funct! dict.func(arg)
  echo 'dict.func called.'
  echo 'argument: '.a:arg
endfunct
funct! dict.callfunc_passself(arg)
  call call(self.func, [a:arg], self)
endfunct
funct! dict.callfunc_nopassself(arg)
  call call(self.func, [a:arg])
endfunct

funct! Func(arg)
  echo "Func called."
  echo 'argument: '.a:arg
endfunct


call dict.callfunc_passself('argument supplied to dict.callfunc')
  " dict.func called.
  " argument: argument supplied to dict.callfunc
call dict.callfunc_nopassself('argument supplied to dict.callfunc')
  " E725: Calling dict function without Dictionary: 37

let dict.func = function('Func')
call dict.callfunc_passself('argument supplied to dict.callfunc')
  " Func called.
  " argument: argument supplied to dict.callfunc
call dict.callfunc_nopassself('argument supplied to dict.callfunc')
  " Func called.
  " argument: argument supplied to dict.callfunc

So as long as the call to the [non-]dictionary function from within the dictionary function passes self as the third parameter to call, then this will work quite well.

This means that in addition to being able to build inheritance structures using cloned-and-modified dictionaries (ie copy prototyping) it’s possible to have some of the methods be references to non-dictionary functions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:24:45+00:00Added an answer on May 14, 2026 at 4:24 am

    All dictionary functions require some dictionary provided as the third argument to call(). All anonymous functions are dictionary functions. All functions that are declared using function dict.func() are anonymous. Just supply {} as the third argument to all call() calls and forget about this.

    And reread the documentation. Self is available in your function. Documentation says that self won’t become available if you do this: let dict.func=function("Foo").

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 343k
  • Answers 343k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): Caused by: java.lang.NullPointerException 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at… May 14, 2026 at 5:29 am
  • Editorial Team
    Editorial Team added an answer The problem could be solved using a loop on a… May 14, 2026 at 5:29 am
  • Editorial Team
    Editorial Team added an answer Depending on the browser it will use either the built-in… May 14, 2026 at 5:29 am

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.