-
-
Notifications
You must be signed in to change notification settings - Fork 606
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
Issue 6365 - Multiple var declaration (AutoTupleDeclaration) #341
Conversation
What about functions that return multiple values of different types? Would this work?
|
Yes. In your case, (double x, int y) = fun(); is just translated to auto __tup = fun(); double x = __tup[0]; // __tup[0] has a type that is implicitly convertible to double int y = __tup[1]; // ditto Therefore, |
I love this idea. Is there any language design-level reason why it shouldn't be included or are we just waiting for Walter to get around to merging it? |
Bump, this is really sexy. |
On looking at this again one concern I see is the implicit temporary. This is caused by creating __tup and would cause postblits to run an extra time in cases where structs are being copied. This may not matter, though, since we're trying to discourage designs where structs can be arbitrarily expensive to copy. |
Bump, any news on this? |
@WalterBright what ya think about this? |
Bump, really looking forward to seeing this merged in. The simplicity of tuples is not going away :). |
Bump, bump, bump. Do want! |
This is just awesome. I have a question, does it work on function declarations? Like |
@robik Unfortunately, no. This enhancement just supports distributing tuple fields to each variables in initializing. |
LGTM 👍 |
+1. |
Documentation for this enhancement: dlang/dlang.org#160 |
Just to give a bit of feedback - we're looking into this. If we conclude that this language addition solves most of the issues with tuples (so no radical redesign is needed), we'll pull this in. We don't want to pull this thinking that it might hurt a better future design. |
What might be hurt in the future? Syntax? Semantics? or ABI issue? |
Syntax and semantics mostly. Walter and I are worried about overarching design more than anything. Consider that the "perfect" tuples for D are six good design decisions away. This pull request deals with destructuring and makes one decision, which is shaping all future decisions. If we later conclude tuples need some additional form of destructuring, or something different entirely, we'll have to add that too. And then some other stuff on top of that. So instead of making one move at a time and then analyzing the result, we want to think the strategy forward so as to have a good overal design, not (only) a good design for destructuring. Now, it's quite possible that destructuring is about all we need, or that whatever else we need doesn't interact badly with destructuring. In that case this request will be pulled, and everybody will be happy. |
Thanks for your answer, @andralex . I cannot reply to your worry immediately, but I also would like to think about it. |
I'd like to be able to ignore a return value if that's possible. For example
That way I don't have to forcefully introduce new symbol names into the current scope (using _ is a nogo because there might already be such a symbol, e.g. in foreach loops or a previous tuple destruction). |
Size optimisation of std.datetime (saves 12KB)
I agree with Andrei, while I don't see anything obviously wrong with this proposal, I'd like to see a complete tuple design before committing ourselves to one aspect of it. |
Copy-paste error
Remove unimplemented method
ddoc strings const correct
Remove unused struct 'Environment'
Take address explicitly
Issue 9635 - Improve message on missing 'this' diagnostics.
Issue 8902 - Unexpected "duplicate union initialization for X" error
Issue 9136 - Add isNested trait for aggregates and functions
http://d.puremagic.com/issues/show_bug.cgi?id=6365
Based on #321, declare multiple variables at once, and initialize them in the corresponding tuple fields.
Syntax:
TupleTypeList is similar to ForeachTypeList.
If you want to write left parenthesis at beginning, you cannot omit the type or storage class of first variable.