Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing functions as arguments and then calling them does not yet quite work in the langium-lox example language interpreter #4

Open
tkueeu opened this issue Aug 20, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@tkueeu
Copy link

tkueeu commented Aug 20, 2023

This example from basic.lox

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.

@msujew msujew added the bug Something isn't working label Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants