language · language ·

Constructors, methods, static methods, and this

A constructor is a same-name method inside a type. Instance methods can read this, while static methods belong to the type itself.

complete-programcpudatalanguagestaticthisyeho

Use a constructor to establish valid starting data, an instance method for behavior that belongs to one value, and static only when no instance state is needed.

Name(Type value) { this.field = value }
Method(...) -> Type { ... }
static Method(...) -> Type { ... }

Status: stable

Self contained reference link

Use a constructor to establish valid starting data, an instance method for behavior that belongs to one value, and static only when no instance state is needed.

cpu · complete-program · type checked

external class referenceCounter
{
    int value

    referenceCounter(int value)
    {
        this.value = value
    }

    Bump() returns int
    {
        this.value = this.value + 1
        return this.value
    }
}

referenceCounter counter = referenceCounter(41)
Console.Log(Text.Format("self-contained-reference={0}", counter.Bump()))
project.mech
package = "tests.compiler.selfContainedReferenceLink"
version = "0.1.0"
selfContainedApp = true
Notes and source

Stored constructor values follow declaration order for the current value-data ABI.

Class dispatch remains a separate oracle-only boundary even though plain-data constructors and direct admitted calls run through Kyber.

yeho/tests/compiler/kyber/plain-data-constructor/start.yh; tests/compiler/kyber/legalized-call-forms/start.yh