digitalmars.D - The empty statement ";" - when is it useful?
- Andrei Alexandrescu (8/8) Jul 25 2009 D has ";" as the empty statement. In fact I think it's an empty
- Don (2/17) Jul 25 2009
-
Stewart Gordon
(5/9)
Jul 26 2009
- Don (6/17) Jul 28 2009 Yes, you're right, it's asm syntax -- though it's an asm syntax which
- KennyTM~ (3/18) Jul 25 2009 for (; cond; inc) { ... }
- BCS (2/23) Jul 25 2009
- Robert Fraser (2/3) Jul 26 2009 Eww...
- Patrick Kreft (9/10) Jul 25 2009 for ( init ; cond; inc ) ...
- Stewart Gordon (10/11) Jul 26 2009 ForStatement:
- Tim Matthews (5/8) Jul 27 2009 In c++:
-
Stewart Gordon
(14/16)
Jul 26 2009
- Don (7/29) Jul 28 2009 Yes. He's recently the claimed the same thing about the comma operator,
- Christian Kamm (3/5) Jul 28 2009 It's under the heading of 'Expression':
- Don (2/10) Jul 28 2009 Ah, right. I thought I'd seen it once. 'CommaExpression' is a dead link.
- Bill Baxter (8/16) Jul 28 2009 You meant to say it doesn't work for a,b, return a; right?
- Andrei Alexandrescu (15/32) Jul 28 2009 I agree. Walter also mentioned the code generation argument in a
- Daniel Keep (3/46) Jul 28 2009 U comma(T,U)(T a, U b) { return b; }
- Andrei Alexandrescu (4/50) Jul 28 2009 Absolutely! And now that order of evaluation will be defined to be
- Arthur Lloyd (2/5) Jul 28 2009 Sorry, this is probably a newbie question, but.. So instead of return a,...
- Jarrett Billingsley (3/8) Jul 28 2009 typeof(T[$ - 1]) comma(T...)(T args) { return args[$ - 1]; }
- Stewart Gordon (7/19) Jul 28 2009 Still won't solve the problem Andrei rightly pointed out. But this will...
- Jarrett Billingsley (11/34) Jul 28 2009 at
- Stewart Gordon (7/12) Jul 28 2009 What do you understand by the combination of "now" and "will be"?
- Andrei Alexandrescu (23/37) Jul 28 2009 No, sorry. Usually I strive to be precise, but this time I just wasn't.
-
Stewart Gordon
(12/15)
Jul 29 2009
- Andrei Alexandrescu (8/27) Jul 29 2009 This has been a source of long discussion in C++ circles, and Walter and...
- BCS (3/18) Jul 29 2009 You could go with "apparent order", that is the code can work anyway it ...
- Andrei Alexandrescu (3/25) Jul 29 2009 That's the plan.
- Stewart Gordon (7/13) Jul 29 2009 So the compiler would be allowed to parallelise only if it can determine...
- Andrei Alexandrescu (6/20) Jul 29 2009 Quite the contrary, in fact. Involved calculations in a given expression...
- Jarrett Billingsley (7/20) Jul 28 2009 http://www.digitalmars.com/d/archives/digitalmars/D/assignment_left-to-r...
- Stewart Gordon (8/16) Jul 29 2009 In which Walter hasn't posted anything ... unless the archiver dropped i...
- Andrei Alexandrescu (4/11) Jul 28 2009 I think he just means that the comma operator is not a strategic
- Don (5/23) Jul 28 2009 The only time I've considered using comma is with: assert(a); b =
- Arthur Lloyd (12/14) Jul 29 2009 If the comma operator does not offer a strategic advantage, will it be d...
- Adam D. Ruppe (7/14) Jul 29 2009 It also seems very verbose in D where you can do:
- Arthur Lloyd (2/15) Jul 29 2009 No, that looks quite good. Is the tuple() a D2 feature? D1/Tango doesn't...
- Adam D. Ruppe (10/11) Jul 29 2009 It is part of phobos 2, in std.typecons. (so you'd actually need to stic...
- Arthur Lloyd (6/19) Jul 29 2009 Does the language get too complex if this feature "gets in"? I mean you ...
D has ";" as the empty statement. In fact I think it's an empty declaration because it can appear at top level. When is it any good? The only place I can think of is after a label blah: ; But then you can always say blah: {} which is arguably less puzzling. Any other places? Andrei
Jul 25 2009
Andrei Alexandrescu wrote:D has ";" as the empty statement. In fact I think it's an empty declaration because it can appear at top level. When is it any good? The only place I can think of is after a label blah: ; But then you can always say blah: {}Except in an asm block. Can't think of anything else.which is arguably less puzzling. Any other places? Andrei
Jul 25 2009
Don wrote:Andrei Alexandrescu wrote:<snip><snip> But an asm block doesn't contain D statements, so that's another matter. Stewart.blah: {}Except in an asm block. Can't think of anything else.
Jul 26 2009
Stewart Gordon wrote:Don wrote:Yes, you're right, it's asm syntax -- though it's an asm syntax which only exists in D, is copied from the D syntax, and which is actually odd and a bit annoying. (It's particularly annoying in the case where the next line is a version statement).Andrei Alexandrescu wrote:<snip><snip> But an asm block doesn't contain D statements, so that's another matter. Stewart.blah: {}Except in an asm block. Can't think of anything else.
Jul 28 2009
Andrei Alexandrescu wrote:D has ";" as the empty statement. In fact I think it's an empty declaration because it can appear at top level. When is it any good? The only place I can think of is after a label blah: ; But then you can always say blah: {} which is arguably less puzzling. Any other places? Andreifor (; cond; inc) { ... } or as the result of a string mixin?
Jul 25 2009
Hello KennyTM~,Andrei Alexandrescu wrote:for({} false; 42) {}D has ";" as the empty statement. In fact I think it's an empty declaration because it can appear at top level. When is it any good? The only place I can think of is after a label blah: ; But then you can always say blah: {} which is arguably less puzzling. Any other places? Andreifor (; cond; inc) { ... }or as the result of a string mixin?
Jul 25 2009
BCS wrote:for({} false; 42) {}Eww...
Jul 26 2009
KennyTM~ Wrote:for (; cond; inc) { ... }for ( init ; cond; inc ) ... init and inc are in the most programming language deducible to empty, but the resulting ';' isnt a empty statement so this us legal code: void main(string[] args) { for(;false;) { } }
Jul 25 2009
KennyTM~ wrote: <snip>for (; cond; inc) { ... }ForStatement: for (Initialize Test; Increment) ScopeStatement Initialize: ; NoScopeNonEmptyStatement a syntactic form in its own right, so irrelevant to the general case of ; as a statement. Stewart.
Jul 26 2009
On Sun, 26 Jul 2009 02:30:56 +0800 KennyTM~ <kennytm gmail.com> wrote:for (; cond; inc) { ... }In c++: #define ever ;; for(ever) { ... }
Jul 27 2009
Andrei Alexandrescu wrote:D has ";" as the empty statement. In fact I think it's an empty declaration because it can appear at top level.<snip> That's always been one of my peeves. At least, ever since I discovered that preventing such common C typos as if (...); { ... } isn't implemented by disallowing ";" as a statement altogether, even though at the time there was nothing in the spec to _allow_ it. http://d.puremagic.com/issues/show_bug.cgi?id=327 Walter once claimed that it's useful for automatically generated code. Though I'm still not quite sure how. Stewart.
Jul 26 2009
Stewart Gordon wrote:Andrei Alexandrescu wrote:Yes. He's recently the claimed the same thing about the comma operator, but I don't buy that argument. I've never needed to use either of them myself. (In the case of comma, sure it works as a sequence point when you have: a,b, return a; but it doesn't work for a,b, return b; which is 50% of the cases. I think it's a fallacious argument). Interestingly CommaExpression doesn't seem to be defined anywhere in the D spec.D has ";" as the empty statement. In fact I think it's an empty declaration because it can appear at top level.<snip> That's always been one of my peeves. At least, ever since I discovered that preventing such common C typos as if (...); { ... } isn't implemented by disallowing ";" as a statement altogether, even though at the time there was nothing in the spec to _allow_ it. http://d.puremagic.com/issues/show_bug.cgi?id=327 Walter once claimed that it's useful for automatically generated code. Though I'm still not quite sure how.Stewart.
Jul 28 2009
Don wrote:Interestingly CommaExpression doesn't seem to be defined anywhere in the D spec.It's under the heading of 'Expression': http://www.digitalmars.com/d/2.0/expression.html#Expression
Jul 28 2009
Christian Kamm wrote:Don wrote:Ah, right. I thought I'd seen it once. 'CommaExpression' is a dead link.Interestingly CommaExpression doesn't seem to be defined anywhere in the D spec.It's under the heading of 'Expression': http://www.digitalmars.com/d/2.0/expression.html#Expression
Jul 28 2009
On Tue, Jul 28, 2009 at 12:09 AM, Don<nospam nospam.com> wrote:You meant to say it doesn't work for a,b, return a; right? And I don't think that would be 50% of the cases. a,b,return b seems much more common. But either way the argument is ridiculous. It doesn't need to be as basic an operator as a single comma just for the sake of making code generation easier. --bbWalter once claimed that it's useful for automatically generated code. Though I'm still not quite sure how.Yes. He's recently the claimed the same thing about the comma operator, but I don't buy that argument. I've never needed to use either of them myself. (In the case of comma, sure it works as a sequence point when you have: a,b, return a; but it doesn't work for a,b, return b; which is 50% of the cases. I think it's a fallacious argument). Interestingly CommaExpression doesn't seem to be defined anywhere in the D spec.
Jul 28 2009
Bill Baxter wrote:On Tue, Jul 28, 2009 at 12:09 AM, Don<nospam nospam.com> wrote:I agree. Walter also mentioned the code generation argument in a conversation with me, fully expecting something like "hell yeah" from me, but was disappointed :o). If he were right and the comma operator would be a net win for better code generation, it would be a net win for better handwritten code. But it's not for either; it is some win, but minor. Anyway, if I had my way I'd eliminate the empty statement ";". It's just uselessly hanging in there. It adds half a page total to TDPL just because I must first define it and then explain for all of if, while, switch, for, foreach... that they can't control an empty statement. If the empty statement didn't exist in the first place, I wouldn't be wasting readers' time. BTW, the use of ";" in foreach is not a problem; that use could be easily defined as sheer punctuation. AndreiYou meant to say it doesn't work for a,b, return a; right? And I don't think that would be 50% of the cases. a,b,return b seems much more common. But either way the argument is ridiculous. It doesn't need to be as basic an operator as a single comma just for the sake of making code generation easier.Walter once claimed that it's useful for automatically generated code. Though I'm still not quite sure how.Yes. He's recently the claimed the same thing about the comma operator, but I don't buy that argument. I've never needed to use either of them myself. (In the case of comma, sure it works as a sequence point when you have: a,b, return a; but it doesn't work for a,b, return b; which is 50% of the cases. I think it's a fallacious argument). Interestingly CommaExpression doesn't seem to be defined anywhere in the D spec.
Jul 28 2009
Andrei Alexandrescu wrote:Bill Baxter wrote:U comma(T,U)(T a, U b) { return b; } Is there any reason you couldn't use something like that?On Tue, Jul 28, 2009 at 12:09 AM, Don<nospam nospam.com> wrote:I agree. Walter also mentioned the code generation argument in a conversation with me, fully expecting something like "hell yeah" from me, but was disappointed :o). If he were right and the comma operator would be a net win for better code generation, it would be a net win for better handwritten code. But it's not for either; it is some win, but minor. Anyway, if I had my way I'd eliminate the empty statement ";". It's just uselessly hanging in there. It adds half a page total to TDPL just because I must first define it and then explain for all of if, while, switch, for, foreach... that they can't control an empty statement. If the empty statement didn't exist in the first place, I wouldn't be wasting readers' time. BTW, the use of ";" in foreach is not a problem; that use could be easily defined as sheer punctuation. AndreiYou meant to say it doesn't work for a,b, return a; right? And I don't think that would be 50% of the cases. a,b,return b seems much more common. But either way the argument is ridiculous. It doesn't need to be as basic an operator as a single comma just for the sake of making code generation easier.Walter once claimed that it's useful for automatically generated code. Though I'm still not quite sure how.Yes. He's recently the claimed the same thing about the comma operator, but I don't buy that argument. I've never needed to use either of them myself. (In the case of comma, sure it works as a sequence point when you have: a,b, return a; but it doesn't work for a,b, return b; which is 50% of the cases. I think it's a fallacious argument). Interestingly CommaExpression doesn't seem to be defined anywhere in the D spec.
Jul 28 2009
Daniel Keep wrote:Andrei Alexandrescu wrote:Absolutely! And now that order of evaluation will be defined to be left-to-right in D, the semantics would be quite the same. AndreiBill Baxter wrote:U comma(T,U)(T a, U b) { return b; } Is there any reason you couldn't use something like that?On Tue, Jul 28, 2009 at 12:09 AM, Don<nospam nospam.com> wrote:I agree. Walter also mentioned the code generation argument in a conversation with me, fully expecting something like "hell yeah" from me, but was disappointed :o). If he were right and the comma operator would be a net win for better code generation, it would be a net win for better handwritten code. But it's not for either; it is some win, but minor. Anyway, if I had my way I'd eliminate the empty statement ";". It's just uselessly hanging in there. It adds half a page total to TDPL just because I must first define it and then explain for all of if, while, switch, for, foreach... that they can't control an empty statement. If the empty statement didn't exist in the first place, I wouldn't be wasting readers' time. BTW, the use of ";" in foreach is not a problem; that use could be easily defined as sheer punctuation. AndreiYou meant to say it doesn't work for a,b, return a; right? And I don't think that would be 50% of the cases. a,b,return b seems much more common. But either way the argument is ridiculous. It doesn't need to be as basic an operator as a single comma just for the sake of making code generation easier.Walter once claimed that it's useful for automatically generated code. Though I'm still not quite sure how.Yes. He's recently the claimed the same thing about the comma operator, but I don't buy that argument. I've never needed to use either of them myself. (In the case of comma, sure it works as a sequence point when you have: a,b, return a; but it doesn't work for a,b, return b; which is 50% of the cases. I think it's a fallacious argument). Interestingly CommaExpression doesn't seem to be defined anywhere in the D spec.
Jul 28 2009
Daniel Keep Wrote:U comma(T,U)(T a, U b) { return b; } Is there any reason you couldn't use something like that?Sorry, this is probably a newbie question, but.. So instead of return a, b, c; you now have to write return comma(a, comma(b, c)); ? How will that help?
Jul 28 2009
Tue, Jul 28, 2009 at 2:28 PM, Arthur Lloyd<via google.com> wrote:Daniel Keep Wrote:typeof(T[$ - 1]) comma(T...)(T args) { return args[$ - 1]; } There. Now you can do "comma(a, b, c)".U comma(T,U)(T a, U b) { return b; } Is there any reason you couldn't use something like that?Sorry, this is probably a newbie question, but.. So instead of return a, b, c; you now have to write return comma(a, comma(b, c)); ? How will that help?
Jul 28 2009
Jarrett Billingsley wrote:Tue, Jul 28, 2009 at 2:28 PM, Arthur Lloyd<via google.com> wrote:Still won't solve the problem Andrei rightly pointed out. But this will: T[$-1] comma(T...)(lazy T args) { foreach (a; args[0..$-1]) cast(void) a; return args[$-1]; } Stewart.Daniel Keep Wrote:typeof(T[$ - 1]) comma(T...)(T args) { return args[$ - 1]; } There. Now you can do "comma(a, b, c)".U comma(T,U)(T a, U b) { return b; } Is there any reason you couldn't use something like that?Sorry, this is probably a newbie question, but.. So instead of return a, b, c; you now have to write return comma(a, comma(b, c)); ? How will that help?
Jul 28 2009
On Tue, Jul 28, 2009 at 5:46 PM, Stewart Gordon<smjg_1998 yahoo.com> wrote:Jarrett Billingsley wrote:,=A0Tue, Jul 28, 2009 at 2:28 PM, Arthur Lloyd<via google.com> wrote:Daniel Keep Wrote:U comma(T,U)(T a, U b) { return b; } Is there any reason you couldn't use something like that?Sorry, this is probably a newbie question, but.. So instead of return a=atb, c; you now have to write return comma(a, comma(b, c)); ? How will th=l:Still won't solve the problem Andrei rightly pointed out. =A0But this wil=help?typeof(T[$ - 1]) comma(T...)(T args) { return args[$ - 1]; } There. =A0Now you can do "comma(a, b, c)".T[$-1] comma(T...)(lazy T args) { =A0 =A0foreach (a; args[0..$-1]) cast(void) a; =A0 =A0return args[$-1]; }For one, that's almost verbatim what Tom S suggested in "comma expressions must die." For two, what problem did Andrei point out? Order of evaluation of function arguments? On the contrary, he said "now that order of evaluation will be defined to be left-to-right in D, the semantics would be quite the same". Your code is what you'd have to use in D1, but in D2, the simpler version would suffice.
Jul 28 2009
Jarrett Billingsley wrote: <snip>For two, what problem did Andrei point out? Order of evaluation of function arguments? On the contrary, he said "now that order of evaluation will be defined to be left-to-right in D, the semantics would be quite the same". Your code is what you'd have to use in D1, but in D2, the simpler version would suffice.What do you understand by the combination of "now" and "will be"? I understood that he was speaking either sarcastically or hypothetically. Or can you find any official statement of this change, let alone a rationale for it? Stewart.
Jul 28 2009
Stewart Gordon wrote:Jarrett Billingsley wrote: <snip>No, sorry. Usually I strive to be precise, but this time I just wasn't. The plan is to define order of evaluation to be lexical order. Somehow I can't convince Walter that that means assignment too! e1[e2] = e3; means: 1. Evaluate e1 2. Evaluate e2 3. Evaluate [] 4. Evaluate e3 5. Evaluate assignment. Walter wants: 1. Evaluate e3. Why in the world, I have no idea. 2, 3. Evaluate e1 and e2, I'm not sure in which order he thinks is right 4. Evaluate [] 4. Evaluate = Lexical order rules. Lexical order dammit! Walter and I see eye to eye probably 95% of the time, which has two disadvantages: (a) everybody here thinks one is influencing the other when in fact most of the time we arrive at the same conclusion from very different paths, (b) the remaining 5% are disconcerting. This is one of those cases. AndreiFor two, what problem did Andrei point out? Order of evaluation of function arguments? On the contrary, he said "now that order of evaluation will be defined to be left-to-right in D, the semantics would be quite the same". Your code is what you'd have to use in D1, but in D2, the simpler version would suffice.What do you understand by the combination of "now" and "will be"? I understood that he was speaking either sarcastically or hypothetically. Or can you find any official statement of this change, let alone a rationale for it?
Jul 28 2009
Andrei Alexandrescu wrote: <snip>No, sorry. Usually I strive to be precise, but this time I just wasn't. The plan is to define order of evaluation to be lexical order. Somehow I can't convince Walter that that means assignment too!<snip> I still would like to know where you found that plan! The decision to leave order of evaluation unspecified was a deliberate one at the time, and for good reasons. One of these reasons was to open the option of evaluating subexpressions in parallel. I'm not sure what the others were, but another optimisation potential that comes to my mind is to minimise the working memory while still allowing expressions to be written in an intuitive order. Who has decided that these reasons are no longer good, and why? Stewart.
Jul 29 2009
Stewart Gordon wrote:Andrei Alexandrescu wrote: <snip>This has been a source of long discussion in C++ circles, and Walter and I have also discussed the matter several times. Defining order of evaluation has good benefits, and the loss in efficiency has with time been reduced to just a few corner cases that don't seem to justify the cost anymore. Note that operations can still be evaluated in parallel as long as there's no dependencies between them. AndreiNo, sorry. Usually I strive to be precise, but this time I just wasn't. The plan is to define order of evaluation to be lexical order. Somehow I can't convince Walter that that means assignment too!<snip> I still would like to know where you found that plan! The decision to leave order of evaluation unspecified was a deliberate one at the time, and for good reasons. One of these reasons was to open the option of evaluating subexpressions in parallel. I'm not sure what the others were, but another optimisation potential that comes to my mind is to minimise the working memory while still allowing expressions to be written in an intuitive order. Who has decided that these reasons are no longer good, and why?
Jul 29 2009
Reply to Andrei,Stewart Gordon wrote:You could go with "apparent order", that is the code can work anyway it wants as long as the end effect is the same as if the order was per the spec.One of these reasons was to open the option of evaluating subexpressions in parallel. I'm not sure what the others were, but another optimisation potential that comes to my mind is to minimise the working memory while still allowing expressions to be written in an intuitive order. Who has decided that these reasons are no longer good, and why?Note that operations can still be evaluated in parallel as long as there's no dependencies between them. Andrei
Jul 29 2009
BCS wrote:Reply to Andrei,That's the plan. AndreiStewart Gordon wrote:You could go with "apparent order", that is the code can work anyway it wants as long as the end effect is the same as if the order was per the spec.One of these reasons was to open the option of evaluating subexpressions in parallel. I'm not sure what the others were, but another optimisation potential that comes to my mind is to minimise the working memory while still allowing expressions to be written in an intuitive order. Who has decided that these reasons are no longer good, and why?Note that operations can still be evaluated in parallel as long as there's no dependencies between them. Andrei
Jul 29 2009
Andrei Alexandrescu wrote: <snip>This has been a source of long discussion in C++ circles, and Walter and I have also discussed the matter several times. Defining order of evaluation has good benefits, and the loss in efficiency has with time been reduced to just a few corner cases that don't seem to justify the cost anymore. Note that operations can still be evaluated in parallel as long as there's no dependencies between them.So the compiler would be allowed to parallelise only if it can determine that the two subexpressions don't depend on each other? This could get complicated when you consider calculations that are involved enough to be worth parallelising in the first place. Stewart.
Jul 29 2009
Stewart Gordon wrote:Andrei Alexandrescu wrote: <snip>Yes.This has been a source of long discussion in C++ circles, and Walter and I have also discussed the matter several times. Defining order of evaluation has good benefits, and the loss in efficiency has with time been reduced to just a few corner cases that don't seem to justify the cost anymore. Note that operations can still be evaluated in parallel as long as there's no dependencies between them.So the compiler would be allowed to parallelise only if it can determine that the two subexpressions don't depend on each other?This could get complicated when you consider calculations that are involved enough to be worth parallelising in the first place.Quite the contrary, in fact. Involved calculations in a given expression entail more often than not complicated operations as opposed to complicated updates. Andrei
Jul 29 2009
On Tue, Jul 28, 2009 at 7:46 PM, Stewart Gordon<smjg_1998 yahoo.com> wrote:Jarrett Billingsley wrote: <snip>aleFor two, what problem did Andrei point out? =A0Order of evaluation of function arguments? =A0On the contrary, he said "now that order of evaluation will be defined to be left-to-right in D, the semantics would be quite the same". =A0Your code is what you'd have to use in D1, but in D2, the simpler version would suffice.What do you understand by the combination of "now" and "will be"? I understood that he was speaking either sarcastically or hypothetically. Or can you find any official statement of this change, let alone a ration=for it? Stewart.http://www.digitalmars.com/d/archives/digitalmars/D/assignment_left-to-righ= t_or_right-to-left_evaluation_89616.html That's the thread I remember it being discussed on. Also, this is the second time your reply has broken threading, at least on the mailing list..
Jul 28 2009
Jarrett Billingsley wrote:On Tue, Jul 28, 2009 at 7:46 PM, Stewart Gordon<smjg_1998 yahoo.com> wrote:<snip>In which Walter hasn't posted anything ... unless the archiver dropped it.Or can you find any official statement of this change, let alone a rationale for it?http://www.digitalmars.com/d/archives/digitalmars/D/assignment_left-to-right_or_right-to-left_evaluation_89616.html That's the thread I remember it being discussed on.Also, this is the second time your reply has broken threading, at least on the mailing list..It hasn't broken threading as I view it in Thunderbird. It sounds to me like a bug in the mailing list. Is anybody else seeing this thread broken (other than through the web interface, where this is a known problem)? Stewart.
Jul 29 2009
Arthur Lloyd wrote:Daniel Keep Wrote:I think he just means that the comma operator is not a strategic advantage for automated code generation. AndreiU comma(T,U)(T a, U b) { return b; } Is there any reason you couldn't use something like that?Sorry, this is probably a newbie question, but.. So instead of return a, b, c; you now have to write return comma(a, comma(b, c)); ? How will that help?
Jul 28 2009
Bill Baxter wrote:On Tue, Jul 28, 2009 at 12:09 AM, Don<nospam nospam.com> wrote:Yes.You meant to say it doesn't work for a,b, return a; right?Walter once claimed that it's useful for automatically generated code. Though I'm still not quite sure how.Yes. He's recently the claimed the same thing about the comma operator, but I don't buy that argument. I've never needed to use either of them myself. (In the case of comma, sure it works as a sequence point when you have: a,b, return a; but it doesn't work for a,b, return b; which is 50% of the cases. I think it's a fallacious argument). Interestingly CommaExpression doesn't seem to be defined anywhere in the D spec.And I don't think that would be 50% of the cases. a,b,return b seems much more common.The only time I've considered using comma is with: assert(a); b = foo(a); assert(c); return b; But you're probably right, it's less than 50% of the time in practice.But either way the argument is ridiculous. It doesn't need to be as basic an operator as a single comma just for the sake of making code generation easier. --bb
Jul 28 2009
Andrei Alexandrescu Wrote:I think he just means that the comma operator is not a strategic advantage for automated code generation.If the comma operator does not offer a strategic advantage, will it be deprecated in favor of something that python and ruby do. I've many times fallen into a trap when initializing multidim arrays, like: Also seems very verbose when in a scripting language I can do: Does this work, if the comma builds a tuple instead of a sequence?
Jul 29 2009
On Wed, Jul 29, 2009 at 10:29:51AM -0400, Arthur Lloyd wrote:Also seems very verbose when in a scripting language I can do:It also seems very verbose in D where you can do: auto getThem() { return tuple(4,5); } auto a = getThem; -- Adam D. Ruppe http://arsdnet.net
Jul 29 2009
Adam D. Ruppe Wrote:On Wed, Jul 29, 2009 at 10:29:51AM -0400, Arthur Lloyd wrote:No, that looks quite good. Is the tuple() a D2 feature? D1/Tango doesn't seem to have it? Why not even go so far as to make the tuple keyword completely optional?Also seems very verbose when in a scripting language I can do:It also seems very verbose in D where you can do: auto getThem() { return tuple(4,5); } auto a = getThem;
Jul 29 2009
On Wed, Jul 29, 2009 at 11:00:13AM -0400, Arthur Lloyd wrote:No, that looks quite good. Is the tuple() a D2 feature? D1/Tango doesn't seem to have it? Why not even go so far as to make the tuple keyword completely optional?It is part of phobos 2, in std.typecons. (so you'd actually need to stick import std.typecons; at the top of the file to get that to compile.) Since it is a library solution, there is no actual keyword here, nor can it do the length thing you wanted. But, it does cover the other case quite well, without needing to change the language at all. -- Adam D. Ruppe http://arsdnet.net
Jul 29 2009
Adam D. Ruppe Wrote:On Wed, Jul 29, 2009 at 11:00:13AM -0400, Arthur Lloyd wrote:Does the language get too complex if this feature "gets in"? I mean you don't need to write or but for some reason tuple(1, 2). On the other hand you need to write 'lambda' in python when constructing inline functions. The 'lambda' is omitted in D and 'tuple' in Python. So a mixture of these languages could omit both!No, that looks quite good. Is the tuple() a D2 feature? D1/Tango doesn't seem to have it? Why not even go so far as to make the tuple keyword completely optional?It is part of phobos 2, in std.typecons. (so you'd actually need to stick import std.typecons; at the top of the file to get that to compile.) Since it is a library solution, there is no actual keyword here, nor can it do the length thing you wanted. But, it does cover the other case quite well, without needing to change the language at all.
Jul 29 2009