-
Notifications
You must be signed in to change notification settings - Fork 2
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
Provide a default value syntax #167
Comments
I am unsure how much it helps if unknown elements defaults to a constant instead of an expression. Because we already have the expression concept in the language (and an expressionevaluator for runtime), this shouldn't be too hard to generalize. As a syntax, I'd rather suggest something like the Elvis operator, as that is already used in Xbase expressions for similar context:
or if we want to have something more textual, maybe we could reuse the
or possibly the
I'd like to avoid introducing new keywords (like the |
I did not mean to introduce a new keyword, just a new aggregator class. Of course, a new keyword can enable nicer syntax, if we are willing to put in the work. As for expressions, i.e. default values that can depend on pattern variables, I feel like they would be powerful and useful, but architecturally somewhat more difficult to implement - it is definitely not a simple aggregator in that case. |
In that case, I wouldn't support it as an aggregator as that would directly conflict with a more generic implementation I am sure there would be relevant cases for. Furthermore, adding the "parameter" to the aggregator would also require language extensions, right now an aggregator is a simple class reference. |
Even more powerful variants:
In the latter case, even though this is not an aggregator, pattern parameters |
A very common pattern is retrieving the value of some attribute, or a default value if it does not exist. Instead of a disjunctive pattern, we could simply use an aggregator to provide a default value where there is none:
In the MVP, we should be able to pass a compile-time constant to initialize the aggregator, because it is not always the same default value that we need. Therefore, in addition to the new aggregator class, we also need some new language-level support. I have used the angle brackets here for the parametrization, but concrete syntax is TBD.
The text was updated successfully, but these errors were encountered: