On 23/05/21 4:49 AM, Bram Moolenaar wrote:
Ernie Rael wrote:
> > var F: func = obj.classMethod
> 1. Binding an object with an object method, like a dictionary is bound
> to a function on a dictionary. "obj.classMethod" in the example.
>
> This applies to 1: It will be a new type, as the bound object is
> included, which differs from a function that is not bound.
Seems like making it a new type is more work for no benefit.
There's the vim9script programmers view, and the vim internals view.
It's often not possible to hide the internal view from what users
experience. We do have incomplete types, such as "any" or "func", which
require runtime type checking. That means you don't get errors for
wrong usage during compile time. And at runtime you might get a
different error depending on what type of function is being passed
around.
My primary concern is that a bound-object-method can be used anywhere a
func can be used. Passing it to an existing function that has an argument
declared "arg: func" or to a builtin that expects a funcref. I have one
case that might push the limit
export def Log(msgOrFunc: any, category: string = '')
var msg_type = type(msgOrFunc)
...
elseif msg_type == v:t_func
And there might be additional functionality, e.g. to get the
object that has been bound to.
I was wondering about getting the object. If you can get the object, is is
possible to set the object? If there is something like
setboundobject(bound-object-method, object)
and if the type of object must be assignable to the original object type,
then you you have a variable which is similar to a c++ "pointer to a member
function" except that it includes the object. This would seem to satisfy
the clamoring for using a method as a value. I guess the object could be
any arbitrary type, but that feels much more complicated.
If you mean, whether the type declaration needs to be different, I'm not
sure. Currently a partial isn't declared differently from a function
reference, it might be possible to not have a separate type declaration
when an object is bound to a function. But since the functionality is
different, it might be useful to declare the type in a way that makes
clear this functionality is available.
Is type being used imprecisely? (Like declare versus define)
I can see defining a bound object method differently
var F: func
F = bindobjectmethod(obj, method)
which wouldn't affect any existing code. But if the resulting type
is not t_func that presents compatibility/usage problems.
-ernie
--
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/5e24f842-e126-412c-3ff2-076956f790b1%40raelity.com.