Andy Wokula wrote:

> Am 11.08.2019 um 00:11 schrieb Bram Moolenaar:
> > Currently user functions can be used both without a context and as a
> > method, it is not possible to restrict them to be used as one or the
> > other.  Very often this doesn't matter, the method is the same as the
> > function, passing the base as the first argument.  But questions arise:
> >
> > - What if the function doesn't take an argument, should it not be able
> >    to be used as a method?  Or always result in an error?  Or should we
> >    be able to define a function FooBar() without an argument to be used
> >    as a function and a function FooBar() with an argument to be used as a
> >    method:
> >     func Report()
> >       echo "nothing to report"
> >     endfunc
> >     func Report(msg)
> >       echo "this happened: " .. a:msg
> >     endfunc
> 
> I have a mechanism in place which loads global functions via
> FuncUndefined (similar to DrChip's AsNeeded).
> 
> Now I wonder how to find the right script when the function name alone
> is no longer enough for the lookup.

If you define a normal user function, both available globally and as a
method, then nothing changes.

If you specifically target a method, thus used after -> and not
available without it, we should probably add a MethodUndefined
autocommand.  It would be used first, and only when no results then
FuncUndefined is triggered to find/load any user function.

I'm not sure about methods for a specific type, e.g. only defined for a
list or dict.  I suppose in many cases you have very similar
functionality in both, and might as well define both.

It would be possible to make the type available to the autocommand.  But
it feels like this is getting more complicated than needed.  That is
also the main reason I asked: Do we want/need to select the function
based on the type?  Perhaps we should just keep it simple and have a
function/method always handle all types.

I want to start adding internal functions that are only available as a
method, to avoid "polluting" the global function namespace.  But for the
script writer it doesn't matter if this is one function for all types,
or different functions for each type, the same will happen.  For user
functions it does matter.

-- 
Well, you come from nothing, you go back to nothing...  What have you
lost?  Nothing!
                                -- Monty Python: The life of Brian

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

-- 
-- 
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/201908111627.x7BGRvFO020959%40masaka.moolenaar.net.

Raspunde prin e-mail lui