ELENA-LANG / elena-lang

ELENA is a general-purpose language with late binding. It is multi-paradigm, combining features of functional and object-oriented programming. Rich set of tools are provided to deal with message dispatching : multi-methods, message qualifying, generic message handlers, run-time interfaces
https://elena-lang.github.io/
MIT License
236 stars 26 forks source link

Support lazy creating #541

Closed arakov closed 3 years ago

arakov commented 3 years ago

To support lazy allocation support .! operator. So we could simplify the following code:

List<TapeFunction> a := nil;

//while (...) {
// ...
    if (a == nil)
        a := new List<TapeFunction>();

    a.append(...)
// }

with

//while (...) {
// ...
    a.!append(...)
// }
arakov commented 3 years ago

The code looks like this:

A
{
    foo()
    {
        console.writeLine("bar")
    }
}

public program()
{
    A a;

    a.!foo(); // checking if the variable is nil, and creating if required
}