[Vala] Confusing closure behavior




Hello,

I have come across this weird closure thing.  In other programming
languages, I would expect the closure in t to have a copy of i, but it
only has a reference.  Is it expected?

Best regards,

Vivien


public delegate void Thunk();

public static void run (Thunk t) {
        t ();
}

int main() {
        int i = 0;
        Thunk t = () => {
                stdout.printf ("%d = 0, right?\n", i);
        };
        i = 1;
        run (t);
        return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]