Re: class proposal 2

"Mark Hahn" <[email protected]>
Newsgroups gmane.comp.lang.prothon.user
Message-ID <[email protected]>
Paul Prescod wrote:
> Mark Hahn wrote:
>
>> ...
>> There will be a class object for each class.
>
> I have mixed feelings about having BOTH prototypes AND classes in the
> same language...

Can you elaborate on your concerns?  Is it confusion?  Performance?  Lack of
focus?  I've already given my arguments for why I want classes included,
even though I personally would use naked prototypes for most applications.
I find no conflict between prototypes and classes just as Python found no
conflicts between functions and methods.

>> There will also be a factory object for each class.  Ironically this
>> object will represent the class itself instead of the instances even
>> though it is not the "class object".  Class methods and class
>> variables will be stored here especially the "call_" method that
>> implements the "Class()" constructor.  I will explain how this works
>> in a moment.  This gives a seperate namespace for class attributes.
>
> What about inheritance between class attributes? Is there any?

Good question.  By definition they would have prototypes, but these would
only matter if you looked up a missing attribute of the attribute.  I would
assume this wouldn't happen so it would be a non-issue.  Methods might have
doc strings and stuff, but nothing that should invoke inheritance.

>> If the Class object is called "Klass", then the factory object would
>> be stored in it's attribute as "Klass.class".
>
> I wouldn't call it a factory because the overall class is the factory.
> It is really the container for class attributes.

I only called it a factory in this message.  Nothing is called factory in
the objects themselves.  I'll stop calling it that.  (But Klass.class is the
object that has the call_() method that creates the instances so I thought
that would make it the factory).

>> ---  When an attribute is first being looked up in an immediate
>> object, not an ancestor, and a attribute named "class" exists in the
>> immediate object, that class attribute object is used in the
>> object's place for the
>> lookup. ---
>
> What does "first being looked up" mean? What exactly is the order of
> lookup? Klass.class.foo and then Klass.foo? Or just Klass.class.foo?

Whenever you look up an attribute, you first look it up in an immediate
target object and you only start looking at the prototype chain prototypes
if the attribute is not found in the immediate object.  So "first looked up"
means the first search in the target immediate object.  In "obj.attr", obj
is the immediate object that is searched when the attribute is "first looked
up".

    Klass.method()    # first lookup in Klass -> Klass.class
    kls = Klass()    # first lookup in Klass -> Klass.class
    kls.method()   # first lookup in kls fails, second -> Klass

As you can see, the delegation from the kls instance in the last example
causes the lookup in Klass to not be "the first lookup" so the rule is not
invoked and the instance kls gets the normal instance method.

Darn, I just found a flaw in my scheme.  When one says Klass.method() in
order to do a directed call of an instance method, they will get
Klass.class.method(), not the Klass.method() like they should.  I need to
work on this.  Once again directed method calling is busting my chops.

> Do the instance objects inherit the "class" at all? Or is it just
> gone?

I'm not sure what you mean.  The instances inherit the methods from their
Class object ("Klass" in the example).  They do not inherit anything from
"Klass.class".  (We need to come up with names for these objects since you
took away the factory name).

> One of the nice things about Python is that str_ and call_ for classes
> do the "right thing" by default no matter what happens for instances.
> Does your proposal have that feature?

If I understand you correctly you mean that Klass().class.call_() should
create an instance of Klass by default and Klass.class.str_() should print
the name of the class even if no methods are defined in a class: section.
Yes, the code proposal at the end of the message that I stole from Serge
does exactly that.  I don't know if I made it clear but that code is
actually implemented by the interpreter for all classes, so it will by
default create instances and print class names.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.