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

Define how/when parameter defaults should be used in dynamic function calls #1281

Open
MaryamZi opened this issue Dec 7, 2023 · 0 comments
Labels
Area/Lang Relates to the Ballerina language specification Type/Improvement Enhancement to language design

Comments

@MaryamZi
Copy link
Member

MaryamZi commented Dec 7, 2023

Description:
The closures generated for default values of function parameters are used at compile-time, when arguments are not specified for such parameters, based on the type descriptor of the declared type of the variable that is used as the function-reference. The runtime type descriptor (and parameter defaults and closures) of the referenced function value is not used here (Function call expression).

But, in certain scenarios, default values may also have to be computed at runtime using the closures from the type descriptor of the function value.

  1. Listeners dispatching to service remote or resource methods with defaultable parameters
service / on new http:Listener(9090) {
    resource function get albums(string artist, string? date = ()) returns Album[] {
        
    }
}
  1. Calling a function with defaultable parameters using function:call
function getAlbums(string author, string? date = ()) returns Album[] {
    ...
}

public function main() {
    function fn = getAlbums;
    any|error res = function:call(fn, "Joy");
}

In jBallerina, the default value closures are used in both these cases to compute the arguments for defaultable parameters when arguments are not passed for such a parameter.

Related issues/discussions:

@anupama-pathirage anupama-pathirage added Type/Improvement Enhancement to language design Area/Lang Relates to the Ballerina language specification labels Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Lang Relates to the Ballerina language specification Type/Improvement Enhancement to language design
Projects
None yet
Development

No branches or pull requests

2 participants