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
233 stars 24 forks source link

Generic typecast handler #534

Closed arakov closed 3 years ago

arakov commented 3 years ago

To support dynamic interfaces we have to be able to handle all typecast messages

arakov commented 3 years ago

A code example:

Decorator2
{
    target;

    constructor(target)
    {
        this target := target
    }

    generic()
    {
        console.print("dynamically decorating ");

        __received(target)
    }

    generic cast()
    {
        var type := __received.__getFirstSignatureMember();

        var proxyType := type.__inheritProxy();
        var proxy := proxyType.__newProxy(self);

        var n := proxy.toPrintable();

        ^ __received(proxy);
    }
}
arakov commented 3 years ago

done