Renderingen-US

Experimental through version 1. Version 0 was alpha. This is the first language release: the interface is relatively stable, not frozen. Nothing is promised stable until version 2.

self

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

Refers to the current instance inside a method.

Aliases: self, this

Syntax: self.<member>

Category#

class

Examples#

radix/corpus/reference/keyword/ego/ego.fab (canonical · keyword)#

Refers to the current instance inside a method.

# =============================================================================
# ego — Refers to the current instance inside a method.
# =============================================================================
#
# What this teaches:
#   • Self-reference — `ego.<member>` accesses the current instance's fields and methods inside a class method.
#   • Method definition — functions defined inside a class block receive the instance as `ego`.
#
# Common mistakes:
#   • Using `ego` outside a class method — `ego` is only valid inside methods defined on a class (SEM008).
#
# See also: const, class
# =============================================================================

# ego — current class instance reference
#
# ego.<field>
#
# GRAMMAR:
#   memberExpr inside class method :← 'ego' '.' ident
#
# EXPECTED OUTPUT:
#   capsa: first

class Capsa {
    mut string titulus

    fn narra() → string {
        # ego = the receiver instance
        return "capsa: " + self.titulus
    }
}

main {
    let Capsa capsa ← Capsa { titulus = "prima" }
    print capsa.narra()
}

Expected output:

capsa: prima