-
Notifications
You must be signed in to change notification settings - Fork 213
Dart VM lacks of "arguments" object passed to a Function #3742
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
Comments
Consider this example: void example(int a, String b, {required bool c}) {...} How would the named parameter I assume arguments would be a I think in dart if you could get an arguments object somehow it would make more sense to represent it as a record which would preserve the type information for each of the individual arguments, and support both positional and named members. |
See #1295 |
This may differ from #1295 of the goal is to get the actual arguments, not the post-default-value-assignment parameters. I still don't see the advantage here, when one can just write Function getFullname(name, surname) {
late List arguments = [name, surname];
return () => print('${arguments.first} ${arguments.last}');
} and get the desired effect. Unlike JavaScript, Dart doesn't allow you to pass an arbitrary number of arguments to a function with two parameters, so you always know how many arguments there will at most be. If we get a way to recognize whether an optional parameter was passed an argument or not, you can completely recreate the arguments inside the function. So I don't see the use-case for having the arguments automatically available as a list, when you can just create the list yourself (and it should probably be s record, to not lose the typing). |
Yes, but the reverse is also true. It might be easier (and more straightforward) to provide Which way is better, of course, depends on how "passed" flags are implemented. E.g. the method discussed in #3680 has too many limitations. Other methods might have their quirks too. |
DISCLAIMER: If any of below does not conform to code of conduct, I am willing to adjust (edit) in order to meet the level or requirements expected;
In JavaScript we have
arguments
array-like object (ostensibleList
in Dart) that at run-time evaluates and returns list of arguments passed to a function (if any), consider the example as follows:As far as I do understand, Dart currently does not have anything similar to
arguments
due to its nature of fixed-length list of literal arguments passed to a function (if any) and MUST be evaluated at compile-time, yet I would like to request for comments on this matter considering the modified Example 1, but for Dart, whereas we are re-using keywordlate
asking Dart VM to evaluate arguments at run-time, rather than compile-time, the example as follows:Some of you might write this off at first glance after reading this saying that the keyword
late
indicates a variable that MUST be non-nullable as per Dart language spec., and yes we could make it non-nullable enforcing the Dart's VM to assign an empty List, instead ofnull
, in case of scenario whereas empty list of literal (none of) arguments passed whatsoever.Thank you.
The text was updated successfully, but these errors were encountered: