You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fun returnSum(a: number, b: number): number {
return a + b;
}
// Closures
fun identity(a: (number, number) => number): (number, number) => number {
return a;
}
print identity(returnSum)(1, 2); // prints "3";
currently results in an error Cannot call a non-function
(Actually, the comment 'Closures' is in my view a misnomer, it is 'just' passing a function reference (or value or pointer (?) ) as an argument. The feature of closures is not used here, that the current scope of variables is preserved for the later execution of the function.)
Expected behaviour would be that function identity is called with reference to function as argument, which is returned,
and then apply (1, 2) on that function returnSum and execute it.
The text was updated successfully, but these errors were encountered:
This example from basic.lox
currently results in an error Cannot call a non-function
(Actually, the comment 'Closures' is in my view a misnomer, it is 'just' passing a function reference (or value or pointer (?) ) as an argument. The feature of closures is not used here, that the current scope of variables is preserved for the later execution of the function.)
Expected behaviour would be that function identity is called with reference to function as argument, which is returned,
and then apply (1, 2) on that function returnSum and execute it.
The text was updated successfully, but these errors were encountered: