Loading ...
Sorry, an error occurred while loading the content.
 

calling dictionary functions with call()

Expand Messages
  • Ted
    Hello, 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
    Message 1 of 2 , Mar 31, 2010
      Hello,
      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 restrict the scope of the function name without
      requiring it to be associated with 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

      $ vim --version
      VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Sep 21 2009 11:22:21)
      Included patches: 1-245
      Compiled by buildd@...
      Huge version with GTK2-GNOME GUI. Features included (+) or not (-):
      +arabic +autocmd +balloon_eval +browse ++builtin_terms +byte_offset
      +cindent
      +clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info
      +comments
      +cryptv +cscope +cursorshape +dialog_con_gui +diff +digraphs +dnd -
      ebcdic
      +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path
      +find_in_path
      +float +folding -footer +fork() +gettext -hangul_input +iconv
      +insert_expand
      +jumplist +keymap +langmap +libcall +linebreak +lispindent +listcmds
      +localmap
      +menu +mksession +modify_fname +mouse +mouseshape +mouse_dec
      +mouse_gpm
      -mouse_jsbterm +mouse_netterm -mouse_sysmouse +mouse_xterm
      +multi_byte
      +multi_lang -mzscheme +netbeans_intg -osfiletype +path_extra +perl
      +postscript
      +printer +profile +python +quickfix +reltime +rightleft +ruby
      +scrollbind
      +signs +smartindent -sniff +statusline -sun_workshop +syntax
      +tag_binary
      +tag_old_static -tag_any_white +tcl +terminfo +termresponse
      +textobjects +title
      +toolbar +user_commands +vertsplit +virtualedit +visual +visualextra
      +viminfo
      +vreplace +wildignore +wildmenu +windows +writebackup +X11 -xfontset
      +xim
      +xsmp_interact +xterm_clipboard -xterm_save
      system vimrc file: "$VIM/vimrc"
      user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
      system gvimrc file: "$VIM/gvimrc"
      user gvimrc file: "$HOME/.gvimrc"
      system menu file: "$VIMRUNTIME/menu.vim"
      fall-back for $VIM: "/usr/share/vim"
      Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -
      D_REENTRANT -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/
      include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/
      include/pixman-1 -I/usr/include/freetype2 -I/usr/include/directfb -I/
      usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/
      include -DORBIT2=1 -pthread -D_REENTRANT -I/usr/include/
      libgnomeui-2.0 -I/usr/include/libart-2.0 -I/usr/include/gconf/2 -I/usr/
      include/gnome-keyring-1 -I/usr/include/libgnome-2.0 -I/usr/include/
      libbonoboui-2.0 -I/usr/include/libgnomecanvas-2.0 -I/usr/include/
      gtk-2.0 -I/usr/include/gnome-vfs-2.0 -I/usr/lib/gnome-vfs-2.0/include -
      I/usr/include/orbit-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/
      include -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/
      include/libbonobo-2.0 -I/usr/include/bonobo-activation-2.0 -I/usr/
      include/libxml2 -I/usr/include/pango-1.0 -I/usr/include/gail-1.0 -I/
      usr/include/freetype2 -I/usr/include/atk-1.0 -I/usr/lib/gtk-2.0/
      include -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/
      directfb -I/usr/include/libpng12 -Wall -g -O2 -D_REENTRANT -
      D_GNU_SOURCE -DDEBIAN -I/usr/local/include -D_LARGEFILE_SOURCE -
      D_FILE_OFFSET_BITS=64 -I/usr/lib/perl/5.10/CORE -I/usr/include/
      python2.6 -pthread -I/usr/include/tcl8.4 -D_REENTRANT=1 -
      D_THREAD_SAFE=1 -D_LARGEFILE64_SOURCE=1 -I/usr/lib/ruby/1.8/x86_64-
      linux
      Linking: gcc -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-
      dynamic -Wl,-E -Wl,--as-needed -o vim -lgtk-x11-2.0 -lgdk-x11-2.0 -
      latk-1.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lgio-2.0 -
      lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0
      -lglib-2.0 -lgnomeui-2 -lbonoboui-2 -lgnomevfs-2 -lgnomecanvas-2 -
      lgnome-2 -lpopt -lbonobo-2 -lbonobo-activation -lORBit-2 -lart_lgpl_2 -
      lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -
      lpangocairo-1.0 -lgio-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -
      lgconf-2 -lgthread-2.0 -lrt -lgmodule-2.0 -lgobject-2.0 -lglib-2.0 -
      lXt -lncurses -lselinux -lacl -lgpm -Wl,-E -L/usr/local/lib -L/usr/
      lib/perl/5.10/CORE -lperl -L/usr/lib/python2.6/config -lpython2.6 -L/
      usr/lib -lz -lutil -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-
      functions -L/usr/lib -ltcl8.4 -lieee -lruby1.8 -lrt -lm

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

      To unsubscribe, reply using "remove me" as the subject.
    • Andy Wokula
      ... If it wants a dict, then give it a dict: call call(testdict.funct, [], {}) ... call call(TestdictDotFunct, [], {}) ... Applies when the function is global:
      Message 2 of 2 , Apr 1, 2010
        Am 01.04.2010 04:31, schrieb Ted:
        > Hello,
        > 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 restrict the scope of the function name without
        > requiring it to be associated with 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

        If it wants a dict, then give it a dict:

        call call(testdict.funct, [], {})

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

        call call(TestdictDotFunct, [], {})

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

        Applies when the function is global:
        func! GlobalFunc()
        echo exists("self")
        endfunc
        let testdict.onemorefunc = function("GlobalFunc")

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

        It's because the following implies the dict attribute:

        let testdict = { }
        funct! testdict.funct()
        ...

        HTH (no warranty),
        Andy

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

        To unsubscribe, reply using "remove me" as the subject.
      Your message has been successfully submitted and would be delivered to recipients shortly.