anole-lang / anole

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

[FEATURE] Support OOP #17

Closed mu001999 closed 3 years ago

mu001999 commented 3 years ago

PLAN to support OOP in Anole

mu001999 commented 3 years ago

Currently we can simulate OOP by coding like the following:

@Student(age) {
    @this: {};

    return this;
};

student: Student(10);

println(student.age);

But it is not convenient to implement other aspects of OOP such as interfaces, inheritances and so on in this way. So it is a PLAN to provide some more convenient ways to support in Anole.

Of course, this is a plan and it may not be applied finally in fact.

Just TRY.

mu001999 commented 3 years ago

The way to declare a class in Anole is that using symbol @@ long long ago. But this symbol may cause dazzling and although it is a token in currently but not used in fact. So we decide to remove it and others about it such the old new expression above all.

mu001999 commented 3 years ago

We are considering whether the defined class is an object and whether we could pass it as an argument.

mu001999 commented 3 years ago

As dict {...} and enum {...}, the direct plan is to design declaration of class as class {...} named class-expression. If we do some declarations like @Student: class {...}, the Student is still a variable binded to a class-object, so each class-object doesn't have its own name although we can add other rules like class <name> {...}. The defect of that each class-object is anonymous is unknown yet. Maybe we can consider the variable binded to an anonymous class-object as a alias.

This is considered in PROPOSAL#20

mu001999 commented 3 years ago

Finally, we PLAN to choose the PROPOSAL#20