digitalmars.D.learn - std.stdio.writeln
- Dennis Ritchie (6/6) Mar 09 2015 Hi.
- Adam D. Ruppe (9/10) Mar 09 2015 that's not an array, use [1,2,3] for that.
- John Colvin (12/18) Mar 09 2015 I think this is a misunderstanding about UFCS.
- Dennis Ritchie (4/15) Mar 09 2015 Thanks.
- ketmar (4/6) Mar 09 2015 or at least warn about it. producing a warning for such expression will=...
- Jonathan M Davis via Digitalmars-d-learn (9/15) Mar 09 2015 There's not much point in that. If someone is using the comma operator
- ketmar (7/25) Mar 09 2015 i remember that deprecation was rejected. maybe this is false memory,=20
- Meta (4/12) Mar 09 2015 I think the last time there was a big discussion about this
- Jonathan M Davis via Digitalmars-d-learn (7/20) Mar 10 2015 Yeah. Even Java has that. But IIRC, it was decided that the comma operat...
- ketmar (4/7) Mar 10 2015 sometimes i'm irritated by this, but with `delete`... ah, i hope nobody=...
Hi. Why prints only the last element? import std.stdio; void main() { (1, 2, 3).writeln; // prints 3 }
Mar 09 2015
On Monday, 9 March 2015 at 14:38:41 UTC, Dennis Ritchie wrote:(1, 2, 3).writeln; // prints 3that's not an array, use [1,2,3] for that. What you wrote is a parenthesis expression with comma expressions inside. The comma operator is a bit weird: it works like a semicolon, but in different contexts. So 1,2,3, in this context, means "calculate 1, then calculate 2, then calculate 3, the result is the final one: 3". The 1 and 2 are just discarded because their calculations don't save anything outside.
Mar 09 2015
On Monday, 9 March 2015 at 14:38:41 UTC, Dennis Ritchie wrote:Hi. Why prints only the last element? import std.stdio; void main() { (1, 2, 3).writeln; // prints 3 }I think this is a misunderstanding about UFCS. 1.writeln(2, 3); is the same as writeln(1, 2, 3); and the same as (1).writeln(2, 3); but (1, 2, 3).writeln; is completely different. UFCS is only for the first argument. Yet another excellent example of why we should abolish the comma operator in D.
Mar 09 2015
On Monday, 9 March 2015 at 14:42:35 UTC, Adam D. Ruppe wrote:On Monday, 9 March 2015 at 14:38:41 UTC, Dennis Ritchie wrote:Thanks. On Monday, 9 March 2015 at 14:48:20 UTC, John Colvin wrote:(1, 2, 3).writeln; // prints 3that's not an array, use [1,2,3] for that. What you wrote is a parenthesis expression with comma expressions inside. The comma operator is a bit weird: it works like a semicolon, but in different contexts. So 1,2,3, in this context, means "calculate 1, then calculate 2, then calculate 3, the result is the final one: 3". The 1 and 2 are just discarded because their calculations don't save anything outside.I think this is a misunderstanding about UFCS.Yes.
Mar 09 2015
On Mon, 09 Mar 2015 14:48:19 +0000, John Colvin wrote:Yet another excellent example of why we should abolish the comma operator in D.or at least warn about it. producing a warning for such expression will=20 ring a bell in programmers head: "compiler is unhappy. i definitely doing=20 something wrong here!"=
Mar 09 2015
On Monday, March 09, 2015 15:45:58 ketmar via Digitalmars-d-learn wrote:On Mon, 09 Mar 2015 14:48:19 +0000, John Colvin wrote:There's not much point in that. If someone is using the comma operator correctly, then the warnings would be incredibly annoying. And if we value avoiding comma operator-related bugs over letting folks take advantage of its usefulness enough to consider such a warning, we might as well just deprecate the comma operator and move towards removing it from the language. Either it's there and useful but error-prone, or it's gone. In between just annoys both groups. - Jonathan M DavisYet another excellent example of why we should abolish the comma operator in D.or at least warn about it. producing a warning for such expression will ring a bell in programmers head: "compiler is unhappy. i definitely doing something wrong here!"
Mar 09 2015
On Mon, 09 Mar 2015 13:18:58 -0700, Jonathan M Davis via Digitalmars-d-learn wrote:On Monday, March 09, 2015 15:45:58 ketmar via Digitalmars-d-learn wrote:i remember that deprecation was rejected. maybe this is false memory,=20 though. btw, there are legit uses of comma, in c-style `for`, for example. this=20 should be left intact, i think (oh, can c-style `for` be deprecated too?! ).=On Mon, 09 Mar 2015 14:48:19 +0000, John Colvin wrote:=20 There's not much point in that. If someone is using the comma operator correctly, then the warnings would be incredibly annoying. And if we value avoiding comma operator-related bugs over letting folks take advantage of its usefulness enough to consider such a warning, we might as well just deprecate the comma operator and move towards removing it from the language. Either it's there and useful but error-prone, or it's gone. In between just annoys both groups.Yet another excellent example of why we should abolish the comma operator in D.or at least warn about it. producing a warning for such expression will ring a bell in programmers head: "compiler is unhappy. i definitely doing something wrong here!"
Mar 09 2015
On Monday, 9 March 2015 at 22:00:46 UTC, ketmar wrote:i remember that deprecation was rejected. maybe this is false memory, though. btw, there are legit uses of comma, in c-style `for`, for example. this should be left intact, i think (oh, can c-style `for` be deprecated too?! ).I think the last time there was a big discussion about this everyone agreed that the comma operator in a for loop was acceptable.
Mar 09 2015
On Monday, March 09, 2015 22:29:23 Meta via Digitalmars-d-learn wrote:On Monday, 9 March 2015 at 22:00:46 UTC, ketmar wrote:Yeah. Even Java has that. But IIRC, it was decided that the comma operator in general would be deprecated. I could be wrong though, and it's the sort of thing that could easily be decided and then not actually happen for ages (e.g. it was decided years ago that delete would be deprecated, but it still isn't). - Jonathan M Davisi remember that deprecation was rejected. maybe this is false memory, though. btw, there are legit uses of comma, in c-style `for`, for example. this should be left intact, i think (oh, can c-style `for` be deprecated too?! ).I think the last time there was a big discussion about this everyone agreed that the comma operator in a for loop was acceptable.
Mar 10 2015
On Tue, 10 Mar 2015 01:31:39 -0700, Jonathan M Davis via Digitalmars-d-learn wrote:it's the sort of thing that could easily be decided and then not actually happen for ages (e.g. it was decided years ago that delete would be deprecated, but it still isn't).sometimes i'm irritated by this, but with `delete`... ah, i hope nobody=20 will remember about for for next 20 years.=
Mar 10 2015