Skip to content

Reference from lambda expression to function parameter not possible #1577

@alexanderpann

Description

@alexanderpann
fun a(name: string) = | => name|                                                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                                                    
test case Error [fail] {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
assert  a("test")() equals "test" [C] [1 ms] [error]                       
}                                                                                                                                                                                                                                                                                                                                   

Error message: invalid value detected: invalid null value detected

In the ArgRef interpreter, the value can't be looked up in the environment because it is probably only searched in the context of the lambda expression and not in the parameter list of the function.

If you return a function with at least one argument, there is a workaround:
Assuming you want to return a function with signature number => string, you can bind the parameters to the inner lambda and create a curried function as a result:

fun a(name: string) = |innerName: string, count: number => innerName + " " + count|.bind(name)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions