Skip to content

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

@tkueeu

Description

@tkueeu

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @msujew@tkueeu

        Issue actions

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