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.  And there might be additional functionality, e.g. to get the
object that has been bound to.

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.

When comparing values then the object the function is bound to will also
matter:

        var obj_A1 = A.new()
        var Func_A1 = obj_A1.Method
        var obj_A2 = A.new()
        var Func_A2 = obj_A2.Method
        echo Func_A1 == Func_A2   # result: false

That differs from when the function reference would not bind an object,
thus the type also differs.


> If I have a function today, with a signature like
>      def MyFunc(ArgFunc: func)
> if "obj.callMethod" is a different type, will I be able to do
>      MyFunc(obj.classMethod)
> 
> And "map()" builtin says "{expr2} must be a String or Funcref". Will
>      []->map(obj.classMethod)
> work?

Sure, so long as you pass the right arguments.  It's very similar to
using a partial.

> Assume obj.classMethod has type objMethodType. Once you do
>      var F = obj.classMethod
> Is there a difference between a func and objMethodType as far as
> its use? Is there extra capability or functionality?

See above.

> Of course internally in vim, they are different or maybe
> objMethodType is an extension/subtype of func.

I'm not sure about terminology, but it's very similar to using a partial
versus using a function reference.

-- 
hundred-and-one symptoms of being an internet addict:
49. You never have to deal with busy signals when calling your ISP...because
    you never log off.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20230521114950.DF50B1C0F38%40moolenaar.net.

Raspunde prin e-mail lui