[Gambas-user] Interpreter's treatment of classes

Bruno Félix Rezende Ribeiro oitofelix at ...181...
Sun Apr 13 02:17:01 CEST 2014


Em Sat, 12 Apr 2014 23:52:48 +0200
Benoît Minisini <gambas at ...1...> escreveu:

> I said rubbish, as it already works like that. If you use a gb.Class 
> with something that requests an object, the it is automatically 
> converted to the Class object *except if* the class is
> auto-creatable. In that case it is converted to the automatic hidden
> singleton instance.

You just gave me the last missing piece of the puzzle!  Thank you so
much!

For a given class named 'CLASS' the expression 'CLASS Is Class'
evaluates to 'True' not because 'CLASS' is an instance of the class
'Class', but because in a object context 'CLASS' gets cast to its
introspection object which in its turn is an instance of the class
'Class'.

It's so obvious and clear now!  The interpreter's behavior is perfectly
consistent and unambiguous with respect to this matter.  I feel I owe
you and the operator 'Is' an apology, as I've suggested the
interpreter's behavior was somewhat inconsistent.  Sorry.

In the end it's very good that this has happened.  Now this subject
is solved once and for all, and available in the mailing list for
posterity.

That said, I still would love to have a "pure" class type.  It'd be like
'Class' or 'Object' but it wouldn't cast classes from 'gb.Class' to
'gb.Object'.  That way we could store classes inside variables, make
them accessible under properties and pass them as arguments to methods.
Something like:

  Dim hPureClass As PureClass = MMain

  TypeOf(MMain) ==> gb.Class

  If(hPureClass = Identity(MMain), "Equal", "Not Equal") ==> "Equal"

  Public Sub Identity(hPureClass As PureClass)
    TypeOf(hPureClass) ==> gb.Class
    Return hPureClass
  End

As far as I can see, it would not disrupt any existing code and would
add a feature to the language that allows some things that are not
strictly possible now, for example the implementation of callback
functions by anonymous references to static or dynamic classes.

However, if you happen to think that although being backward compatible
this change would be too big or not worthy, it'd be sufficient,
although not optimal (or so convenient as it could be), to circumvent
the current limitations by being able to (un)cast an introspection
'Class' object to the class it describes, perhaps by a method or
property thereof, intended for immediate use (a little bit like virtual
classes). So it'd look like:

  Dim hClass As Class = MMain

  TypeOf(hClass) ==> gb.Object
  TypeOf(hClass.Class) ==> gb.Class

  If(hClass.Class = MMain, "Equal", "Not Equal") ==> "Equal"

I don't know if it's possible at all given the current implementation
of the interpreter.  In the case it happens to be possible and
relatively easy to implement, it'd solve the biggest drawback presented
in this correspondence.

Thank you for your attention and interest.

Happy Hacking!

-- 
 ,= ,-_-. =.  Bruno Félix Rezende Ribeiro (oitofelix) [0x28D618AF]
((_/)o o(\_)) There is no system but GNU;
 `-'(. .)`-'  GNU Linux-Libre is one of its official kernels;
     \_/      All software must be free as in freedom;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20140412/aa80441f/attachment.sig>


More information about the User mailing list