-
Notifications
You must be signed in to change notification settings - Fork 591
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
[D] Add shortened function definition #3966
Conversation
When strictly following https://dlang.org/spec/function.html#function-bodies would shorthands with FunctionContracts need to be supported as well? int[] map(T)(int[] array) in(array) => 1;
int[] map(T)(int[] array) out(array) => 2;
int[] map(T)(int[] array) in(array) out(array) => 3; Not sure if |
One-line pre/postconditions (AKA
Multi-line pre/postconditions (AKA
You can't use |
The point or question is not about content of parentheses, but rather whether the According to the syntax specs, I'd expect Note: I am reading specs only, I don't have an compiler or sdk installed for testing. |
That is how the syntax already behaves with regular function declaration syntax. Modifying it is not even within the scope of this pull request.
If you read the grammar defined in the spec, you will see that the semicolon in Furthermore, the pathetic cadence and bafflingly reasoned comments I have received from the reviewing of such trivial improvements has been stifling to say the least. There are a whole host of outdated aspects of this syntax that should’ve been fixed years ago, and now I see why nobody has. If I had expected this much friction over a barebones 4 line addition to support a feature added 3 years ago then I would’ve kept my changes upstream. |
According to the following rules extracted from https://dlang.org/spec/function.html#function-bodies
a shortend function definition such as
appears to be valid, while with this PR |
And yet
When you write an int[] map(T)(int[] array) out(; array) => 2;
int[] map(T)(int[] array) in(array) out(; array) => 3;
|
Keep it civil. Your previous post was likewise somewhat lacking in civility. |
Actually I wouldn't have expected a semicolon within the parentheses to make a difference, which is IMHO an over pedantic treatment - not caused by this PR though. A syntax should ideally be able to handle incomplete expressions in sane ways without breaking syntax highlighting - to some extend at least. I therefore haven't realized the difference between Maybe some additional test cases could help verifying those valid forms/variants of a function definition work as expected. With the misanderstanding clarified this PR is correct and valid. |
Well, true. Let's claim disappointment and unfamilarity with how open source projects try to ensure a least level of quality. The truth is all maintainers here just being unpaid volunteers spending their spare time to help improving syntaxes. Most of us with limited time and scope with regards to familiar or used languages/syntaxes. Despite those limitation we can't just merge anything reaching in, if parts of it seem unclear. D is not one of the mainline syntaxes. It's also true, me not studying its specs to the deepest detail because I don't use or need it at all. Still trying to fix bugs, which seem simple to fix, despite limited knowledge about or motivation for it. As such I can just appologize if the attempt to fill some gaps offended anyone. |
Which is exactly why I explained from the outset that you were writing the wrong thing:
Only to be completely run-over by the assertion that what I was saying was irrelevant:
This exercise in not listening to the person telling you exactly what's wrong and is just trying to help you is a waste of everyone's time, which as you pointed out is limited.
There are examples listed in the spec that you could copy and slightly modify, there is an online D compiler to help you check whether your code is even valid. You can also read the 4 lines of the syntax that I changed and come to the logical conclusion that the parts of the syntax that I wrote interact with the aftermath of an out-contract in the exact same way as a regular function declaration, and therefore if something is wrong then it follows that it must be a pre-existing issue with the syntax. In fact, the way that I made shortened function declaration work is so similar to regular function declaration that it even accepts this completely invalid code: int main()
out{} => 3;
I am the one who actually uses this syntax on a day-to-day basis, and I was doing my best to provide you with accurate information about my changes from the beginning, which was ignored ad nauseam.
Please do. |
Fixes #3894.
Changes:
int main() => 0;
) in all its forms: