Re: Re: class proposal 2
Serge Orlov <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <[email protected]> |
Paul Prescod wrote:
> Serge Orlov wrote:
>>...
>> That's two pretty contradictory statements. Will you not add classes or
>> will you search and add? At this point of discussion I pretty much
>> convinced myself how classes (which act like types) should be
>> implemented. I will sit and watch if somebody suggests something
>> better. I'm skeptical today.
> There is too much traffic for me to keep up. Is there one post that
> summarizes your position? My last impression of it was similar to
> Mark's. It did seem as if it was getting complex.
Yeah, the traffic is getting heavier. I'd like to clarify my
opinion on metaclasses. I think they were overdesigned in Python,
they act as decorators. So classes either from Type or .copy() Type
in my proposal, but they are there just to complete the whole
picture so you can find out type of everything. There no a lot
of usage for putting other methods besides .call_() and .str_()
into any metatype, so what I want to do is to kill metaclass
right now. There should be one immutable metaclass named Type
with two simple methods .call_() and .str_(), no other metaclasses
allowed. Classes are defined as:
class Klass(Base1,Base2,...):
class:
<class methods here>
instance:
<instance methods here>
if there are no class methods a short declaration can be used:
class Klass(Base1,Base2,...):
<instance methods here>
No matter how instance methods are defined they are stored
in the prototype instance_ which is an attribute of the Klass.
If you want to make a reference to instance method you can
do it as Klass.instance_.method or shortcut syntax Klass::method.
Direct calls can be spelled as Klass::method(a,b,c) which is
equal to Klass.instance_.method{a}(b,c)
Class methods are stored as attributes of the class. So if you
define
class Klass(Base1,Base2,...):
class:
def fromFile(name):
instance:
def fromFile(a,b,c)
and call Klass.fromFile(s) then *always* class method will be
called without any exceptions for call_, str_ etc...
if you grab the reference Klass.call_ you will get class method,
if you want instance method you will spell it as Klass::call_
All instances inherit from Klass.instance_ prototype. It's
an object that inherits from Base1.instance_, Base2.instance_
and has an attribute .type_ which is equal to Klass. In one
of my letters I said "every object has type_ attribute". This
is incorrect. Every *instance prototype* has type_ attribute
The follow code describes it in code:
class Klass:
pass
k = Klass()
assert k.attrs_() == {}
assert k.type_ is Klass
assert Klass.instance_.attrs_[$type_] is Klass
assert k.protos_[0] is Klass.instance_
I'm sorry, but I don't have time right now to comment on other
proposals, I'll do it later.
-- Serge