On 2023-01-15, Bram Moolenaar <Bram@moolenaar.net> wrote:
>> Is there a way to distinguish the class of the value returned by
>> [a function]?
>
> Currently not. I have been wondering what would be the best way to
> cover this. We already have type(), but this only returns the basic
> type. For example for list<number> and list<string> it returns the same
> value. It can tell the difference between a list and an object, but not
> between two objects from a different class.
>
> You can use typename(), it will include the name of the class. However,
> it is possible to have the same class name in two separate scripts,
> since they are script-local by default. Thus this may make you think
> it's the same class while it is not.
Ah, that would probably be enough for my use case, as the test in my
case is for script-local objects only.
> Using "instanceof" would work in many places, but you would need to
> import the class to be able to use it. If you only want to know if two
> objects are from the same class, that is extra overhead.
>
> Perhaps we need a variant of type() that is specific about the exact
> type. Then it can also be used to tell the difference between
> list<number> and list<string>. This will be some work to implement,
> because this will mean a new variable type.
To me this falls into the "nice to have" category: I think that most use
cases can be rewritten (possibly verbosely and not elegantly) in a way
that the need for this is avoided. I have a possibly related use case,
but I will post about it in another thread.
Thanks for the comprehensive reply!
Life.
--
--
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
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/tq1ob1%24llr%242%40ciao.gmane.io.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment