buzz-language / buzz

👨‍🚀 buzz, A small/lightweight statically typed scripting language
https://buzz-lang.dev
MIT License
1.15k stars 31 forks source link

`Self` as reference to current object type #255

Open giann opened 5 months ago

giann commented 5 months ago

Not really useful in an object declaration since we can self reference there, but useful in protocols where we want to reference the actual object type.

protocol Clonable {
    fun clone() > Self;
}

object(Clonable) Person {
    str name,

    fun clone() > Self {
        return Person { name = this.name };
    }
}