On 23/02/10 12:50 PM, Bram Moolenaar wrote:
For now I'm using

     export def IsInstanceOf(o: any, type: string): bool
          return type(o) == v:t_object && type == typename(o)[7 : -2]
     enddef

Is there something better? A planned builtin?

I don't actually need it yet, but I'm just getting started and I know
how I am.
Implementing "instanceof" is in the todo list.  I haven't looked into
the details yet.  Probably similar to how Java works.  Although I have
always found it a bit confusing that it results in true for an object
that is a child of the class being tested with.

Yeah, In Java's java.lang.Class, there's both "isInstance(Object)" and
"isAssignableFrom(Class<?>); they both basically test assignment compatibility,
same as the languages "instanceof" operator.

And with that reminder, I'm changing the name of my temporary helper class to

   export def IsSameType(o: any, type: string): bool

since it doesn't test assignment compatibility. (And for now don't worry about
same class name but different file.)

-ernie


I have also been thinking of an alternative of type() that includes the
exact class.  So that you could do:

        type_ext(object) == type_ext(SomeClass.new())

Similar to typename(), except that it would make a difference between
classes with the same name declared in different scripts.  Hmm, perhaps
adding the script number would work?  Thus if you define a class MyClass
in script 4 and script 7, you would get:
        object<MyClass/4>
        object<MyClass/7>

This win't work if a class can be defined more than once in one script
file.  E.g. when it's local to a function.  An alternative is to give
each encountered class a unique number.


--
--
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/c5001f6e-9927-edd0-aea2-fdf60f44edc1%40raelity.com.

Raspunde prin e-mail lui