anole-lang / anole

The Anole Programming Language
MIT License
17 stars 1 forks source link

[PROPOSAL] A Proposal of OOP Support #20

Closed mu001999 closed 3 years ago

mu001999 commented 3 years ago

This issue is about a proposal of FEATURE#17 Support OOP which considers class declarations as objects.

mu001999 commented 3 years ago

This PROPOSAL may make classes could be generated dynamically and as values for passing or returning.

mu001999 commented 3 years ago

Add NEW Token class

mu001999 commented 3 years ago

Create a (anonymous) class-object in the following way, and the Bar is the alias of the anonymous class:

@Bar: class {
    ...
};

We enable creating a class-object with a name like that mentioned in FEATURE#17 Support OOP, the name will be recorded as one meta-information. For example:

class Bar {
    ...
};

equals:

@Bar: class Bar {
    ...
};

The second Bar is the unique name for the class-object and the first one is an alias. So if we do in the following way, Foo is an alias of Bar, but we can't create an object of Bar with the name self:

@Foo: class Bar {
    ...
};

That is, we consider all variables as aliases.

mu001999 commented 3 years ago

For details of the definition of one class, the PLANED design of inheriting is as the following:

@Foo: class(Bar) Baz {
    ...
};

As the way mentioned, we can consider the keyword class as a function which receives base classes and then returns a new class-object.

mu001999 commented 3 years ago

For details of definitions of members of one class, the PLANED design is as the following:

class Student {
    data: 0;
    instance_method(self, ...) {
        ....
    };
    class_method(cls, ...) {
        ...
    };
};

Student.class_method(...) makes the first parameter binded to class Student while Student().instance_method(...) makes the first parameter binded to the instance.