request switch statement with common block

2013-08-03 Thread JS
switch (cond) common: always executed code here case A : etc... } instead of if (cond) { always executed code here } switch (cond) case A : etc... } which requires modification of the condition twice when necessary

Re: request switch statement with common block

2013-08-03 Thread Andrej Mitrovic
On Saturday, 3 August 2013 at 14:38:48 UTC, JS wrote: switch (cond) common: always executed code here case A : etc... } instead of if (cond) { always executed code here } switch (cond) case A : etc... } which requires modification of the condition twice when ne

Re: request switch statement with common block

2013-08-03 Thread MattCodr
On Saturday, 3 August 2013 at 14:38:48 UTC, JS wrote: switch (cond) common: always executed code here case A : etc... } instead of if (cond) { always executed code here } switch (cond) case A : etc... } which requires modification of the condition twice when ne

Re: request switch statement with common block

2013-08-03 Thread dennis luehring
Am 03.08.2013 16:38, schrieb JS: switch (cond) common: always executed code here case A : etc... } instead of if (cond) { always executed code here } switch (cond) case A : etc... } which requires modification of the condition twice when necessary s

Re: request switch statement with common block

2013-08-03 Thread Ary Borenszweig
On 8/3/13 11:38 AM, JS wrote: switch (cond) common: always executed code here case A : etc... } instead of if (cond) { always executed code here } switch (cond) case A : etc... } which requires modification of the condition twice when necessary Do you mea

Re: request switch statement with common block

2013-08-03 Thread JS
On Saturday, 3 August 2013 at 16:16:24 UTC, Ary Borenszweig wrote: On 8/3/13 11:38 AM, JS wrote: switch (cond) common: always executed code here case A : etc... } instead of if (cond) { always executed code here } switch (cond) case A : etc... } which requires

Re: request switch statement with common block

2013-08-03 Thread Andrei Alexandrescu
On 8/3/13 10:21 AM, JS wrote: On Saturday, 3 August 2013 at 16:16:24 UTC, Ary Borenszweig wrote: On 8/3/13 11:38 AM, JS wrote: switch (cond) common: always executed code here case A : etc... } instead of if (cond) { always executed code here } switch (cond) case A : etc

Re: request switch statement with common block

2013-08-03 Thread w0rp
I can see you saving a little bit of typing with this, but it's not worth it.

Re: request switch statement with common block

2013-08-03 Thread Walter Bright
On 8/3/2013 10:45 AM, w0rp wrote: I can see you saving a little bit of typing with this, but it's not worth it. It would be a very unconventional syntactic form, and my experience with such things is it'll see very, very little use.

Re: request switch statement with common block

2013-08-03 Thread MattCoder
On Saturday, 3 August 2013 at 18:04:03 UTC, Walter Bright wrote: On 8/3/2013 10:45 AM, w0rp wrote: I can see you saving a little bit of typing with this, but it's not worth it. It would be a very unconventional syntactic form, and my experience with such things is it'll see very, very little

Re: request switch statement with common block

2013-08-03 Thread JS
On Saturday, 3 August 2013 at 17:45:11 UTC, w0rp wrote: I can see you saving a little bit of typing with this, but it's not worth it. Um, it can actually save a lot of type and errors. having two places to change is very error prone. if (cond) { } switch(cond) If the condition is complex an

Re: request switch statement with common block

2013-08-03 Thread JS
On Saturday, 3 August 2013 at 18:51:24 UTC, MattCoder wrote: On Saturday, 3 August 2013 at 18:04:03 UTC, Walter Bright wrote: On 8/3/2013 10:45 AM, w0rp wrote: I can see you saving a little bit of typing with this, but it's not worth it. It would be a very unconventional syntactic form, and

Re: request switch statement with common block

2013-08-03 Thread Andre Artus
On Saturday, 3 August 2013 at 18:56:47 UTC, JS wrote: On Saturday, 3 August 2013 at 17:45:11 UTC, w0rp wrote: I can see you saving a little bit of typing with this, but it's not worth it. Um, it can actually save a lot of type and errors. having two places to change is very error prone. if

Re: request switch statement with common block

2013-08-03 Thread Meta
On Saturday, 3 August 2013 at 19:10:19 UTC, Andre Artus wrote: If the implementation is so obviously trivial why don't you implement a proof of concept? The compiler is open source after all. This seems like something that would be fairly simple to implement using a mixin template, so you may

Re: request switch statement with common block

2013-08-03 Thread Walter Bright
On 8/3/2013 12:00 PM, JS wrote: What I really don't get it is why people think that just because they won't use such a feature then it must be useless to everyone else. You could provide supporting evidence by examining every use of switch in the dmd, phobos, and druntime source code, and see

Re: request switch statement with common block

2013-08-03 Thread H. S. Teoh
On Sat, Aug 03, 2013 at 12:22:53PM -0700, Walter Bright wrote: > On 8/3/2013 12:00 PM, JS wrote: > >What I really don't get it is why people think that just because they > >won't use such a feature then it must be useless to everyone else. > > You could provide supporting evidence by examining eve

Re: request switch statement with common block

2013-08-03 Thread JS
On Saturday, 3 August 2013 at 19:10:19 UTC, Andre Artus wrote: On Saturday, 3 August 2013 at 18:56:47 UTC, JS wrote: On Saturday, 3 August 2013 at 17:45:11 UTC, w0rp wrote: I can see you saving a little bit of typing with this, but it's not worth it. Um, it can actually save a lot of type a

Re: request switch statement with common block

2013-08-03 Thread Dicebot
On Saturday, 3 August 2013 at 19:51:33 UTC, JS wrote: ... I am afraid creating your own language may be your only possibility to get a language that shares your views on "proper" design. Because with each new topic it becomes more and more clear that D is unlikely to fit into that picture.

Re: request switch statement with common block

2013-08-03 Thread JS
On Saturday, 3 August 2013 at 19:22:53 UTC, Walter Bright wrote: On 8/3/2013 12:00 PM, JS wrote: What I really don't get it is why people think that just because they won't use such a feature then it must be useless to everyone else. You could provide supporting evidence by examining every us

Re: request switch statement with common block

2013-08-03 Thread Jonathan M Davis
On Saturday, August 03, 2013 12:35:22 H. S. Teoh wrote: > On Sat, Aug 03, 2013 at 12:22:53PM -0700, Walter Bright wrote: > > On 8/3/2013 12:00 PM, JS wrote: > > >What I really don't get it is why people think that just because they > > >won't use such a feature then it must be useless to everyone e

Re: request switch statement with common block

2013-08-03 Thread bearophile
Regarding the feature proposed here, I think the extra complexity added doesn't pay enough back. Walter Bright: You could provide supporting evidence by examining every use of switch in the dmd, phobos, and druntime source code, and see what percentage of those would benefit from your propos

Re: request switch statement with common block

2013-08-03 Thread H. S. Teoh
On Sat, Aug 03, 2013 at 01:33:44PM -0700, Jonathan M Davis wrote: > On Saturday, August 03, 2013 12:35:22 H. S. Teoh wrote: > > On Sat, Aug 03, 2013 at 12:22:53PM -0700, Walter Bright wrote: [...] > > > Consider, for example, the scope guard statement in D. It is > > > extremely useful - but it is

Re: request switch statement with common block

2013-08-03 Thread Jonathan M Davis
On Saturday, August 03, 2013 14:25:24 H. S. Teoh wrote: > On Sat, Aug 03, 2013 at 01:33:44PM -0700, Jonathan M Davis wrote: > > The only thing that's really missing from C++ that D has that you > > might use in place of scope is finally. > > Truth be told, I think scope trumps finally because it l

Re: request switch statement with common block

2013-08-03 Thread Walter Bright
On 8/3/2013 1:06 PM, JS wrote: On Saturday, 3 August 2013 at 19:22:53 UTC, Walter Bright wrote: On 8/3/2013 12:00 PM, JS wrote: What I really don't get it is why people think that just because they won't use such a feature then it must be useless to everyone else. You could provide supporting

Re: request switch statement with common block

2013-08-03 Thread Walter Bright
On 8/3/2013 12:51 PM, JS wrote: On Saturday, 3 August 2013 at 19:10:19 UTC, Andre Artus wrote: If the implementation is so obviously trivial why don't you implement a proof of concept? because I have better things to do Implying that our time is of lesser value than yours does not help sell y

Re: request switch statement with common block

2013-08-03 Thread H. S. Teoh
On Sat, Aug 03, 2013 at 02:34:51PM -0700, Jonathan M Davis wrote: > On Saturday, August 03, 2013 14:25:24 H. S. Teoh wrote: > > On Sat, Aug 03, 2013 at 01:33:44PM -0700, Jonathan M Davis wrote: [...] > > > I definitely use scope from time to time, but I don't know how > > > frequently I use it in c

Re: request switch statement with common block

2013-08-03 Thread Jonathan M Davis
On Saturday, August 03, 2013 14:49:30 H. S. Teoh wrote: > On Sat, Aug 03, 2013 at 02:34:51PM -0700, Jonathan M Davis wrote: > > On Saturday, August 03, 2013 14:25:24 H. S. Teoh wrote: > > > On Sat, Aug 03, 2013 at 01:33:44PM -0700, Jonathan M Davis wrote: > [...] > > > > > I definitely use scope f

Re: request switch statement with common block

2013-08-03 Thread JS
On Saturday, 3 August 2013 at 21:42:00 UTC, Walter Bright wrote: On 8/3/2013 12:51 PM, JS wrote: On Saturday, 3 August 2013 at 19:10:19 UTC, Andre Artus wrote: If the implementation is so obviously trivial why don't you implement a proof of concept? because I have better things to do Implyi

Re: request switch statement with common block

2013-08-03 Thread Andre Artus
So, depending on how you define "not worth it", which I take "I'm too lazy to implement it", you could be correct. YaAA: If the implementation is so obviously trivial why don't you implement a proof of concept? The compiler is open source after all. JS: because I have better things to do a

Re: request switch statement with common block

2013-08-04 Thread Kagamin
On Saturday, 3 August 2013 at 18:56:47 UTC, JS wrote: Um, it can actually save a lot of type and errors. having two places to change is very error prone. if (cond) { } switch(cond) What is error-prone is evaluation of a complex condition twice assuming it will result in the same value. That'

Re: request switch statement with common block

2013-08-04 Thread John Colvin
On Sunday, 4 August 2013 at 01:57:04 UTC, JS wrote: Stuff like i++(short form) is ONLY for convenience... yet every uses it! NOT because they used it before it exists(obviously) but because the language supported it and then people were able to see how useful it is(and some things take a long t

Re: request switch statement with common block

2013-08-04 Thread H. S. Teoh
On Sat, Aug 03, 2013 at 03:18:49PM -0700, Jonathan M Davis wrote: [...] > Hmmm. For a scope(success) statement to work, the code has to be put > at every successful exit point from the scope. In the simple case, > that means putting it at the end of the try portion of a try-catch > block, but the t

Re: request switch statement with common block

2013-08-04 Thread monarch_dodra
On Saturday, 3 August 2013 at 20:38:37 UTC, bearophile wrote: Regarding the feature proposed here, I think the extra complexity added doesn't pay enough back. Walter Bright: You could provide supporting evidence by examining every use of switch in the dmd, phobos, and druntime source code, a

Re: request switch statement with common block

2013-08-04 Thread Dicebot
On Sunday, 4 August 2013 at 15:32:17 UTC, monarch_dodra wrote: You pique my interest. What is this? Looks like template shorthand? I didn't find nything about it in docs. Could you share some links about this? http://wiki.dlang.org/DIP42

Re: request switch statement with common block

2013-08-04 Thread Andre Artus
On Sunday, 4 August 2013 at 10:14:50 UTC, Kagamin wrote: On Saturday, 3 August 2013 at 18:56:47 UTC, JS wrote: Um, it can actually save a lot of type and errors. having two places to change is very error prone. if (cond) { } switch(cond) What is error-prone is evaluation of a complex conditi

Re: request switch statement with common block

2013-08-04 Thread Andre Artus
On Sunday, 4 August 2013 at 15:57:32 UTC, Andre Artus wrote: On Sunday, 4 August 2013 at 10:14:50 UTC, Kagamin wrote: On Saturday, 3 August 2013 at 18:56:47 UTC, JS wrote: Um, it can actually save a lot of type and errors. having two places to change is very error prone. if (cond) { } switch(

Re: request switch statement with common block

2013-08-04 Thread MattCoder
On Sunday, 4 August 2013 at 16:16:25 UTC, Andre Artus wrote: On Sunday, 4 August 2013 at 15:57:32 UTC, Andre Artus wrote: On Sunday, 4 August 2013 at 10:14:50 UTC, Kagamin wrote: On Saturday, 3 August 2013 at 18:56:47 UTC, JS wrote: Um, it can actually save a lot of type and errors. having tw

Re: request switch statement with common block

2013-08-04 Thread Ali Çehreli
On 08/03/2013 01:38 PM, bearophile wrote: > enum mysize(T) = T.sizeof; That works... > template Pair(T) = Tuple(T, T); Instead, the following works (alias and !): alias Pair(T) = Tuple!(T, T); Is my change right? Ali

Re: request switch statement with common block

2013-08-04 Thread bearophile
Ali Çehreli: > template Pair(T) = Tuple(T, T); Instead, the following works (alias and !): alias Pair(T) = Tuple!(T, T); Is my change right? Your change is right, I didn't give enough attention on the code I wrote, sorry :-) Bye, bearophile

Re: request switch statement with common block

2013-08-04 Thread monarch_dodra
On Sunday, 4 August 2013 at 15:38:01 UTC, Dicebot wrote: On Sunday, 4 August 2013 at 15:32:17 UTC, monarch_dodra wrote: You pique my interest. What is this? Looks like template shorthand? I didn't find nything about it in docs. Could you share some links about this? http://wiki.dlang.org/DIP4

Re: request switch statement with common block

2013-08-04 Thread bearophile
monarch_dodra: Awesome. I'll have to introduce std.traits to this new syntax. That DIP is not updated to what was actually implemented by Kenji. There is support for both enum and alias. But after a good look at my code base I have not found many places where the new syntax is useful. In m

Re: request switch statement with common block

2013-08-04 Thread Walter Bright
On 8/4/2013 11:30 AM, bearophile wrote: monarch_dodra: Awesome. I'll have to introduce std.traits to this new syntax. That DIP is not updated to what was actually implemented by Kenji. There is support for both enum and alias. But after a good look at my code base I have not found many place

Re: request switch statement with common block

2013-08-04 Thread Andre Artus
Andre Artus: int number; string message; switch (number) { default: // valid: ends with 'throw' throw new Exception("unknown number"); case 3: message ~= "three "; break; case 4: message ~= "four "; continue; case 5:

Re: request switch statement with common block

2013-08-04 Thread Andre Artus
On Monday, 5 August 2013 at 04:07:55 UTC, Andre Artus wrote: Andre Artus: int number; string message; switch (number) { default: // valid: ends with 'throw' throw new Exception("unknown number"); case 3: message ~= "three "; break; case 4:

Re: request switch statement with common block

2013-08-04 Thread luminousone
perhaps a more generic solution should be looked at, extend contracts to work with all scope blocks. switch(somenumber) in { ... before stuff ... } out { after stuff ... } body { case 1: in { ... etc } out { ... more etc ... } body {

Re: request switch statement with common block

2013-08-05 Thread Andre Artus
On Monday, 5 August 2013 at 06:28:12 UTC, luminousone wrote: perhaps a more generic solution should be looked at, extend contracts to work with all scope blocks. switch(somenumber) in { ... before stuff ... } out { after stuff ... } body { case 1: in { ... etc

Re: request switch statement with common block

2013-08-05 Thread dennis luehring
Am 05.08.2013 08:28, schrieb luminousone: or perhaps for( int i = 0 ; i < 10 ; i ++ ) in { assert( i == 0 ); } out { assert( i == 9 ); } body { ... stuff ... } that is just evil code if you got something todo before or on the first item of the list do it before the loop - an

Re: request switch statement with common block

2013-08-05 Thread MattCodr
On Monday, 5 August 2013 at 04:07:55 UTC, Andre Artus wrote: Andre Artus: int number; string message; switch (number) { default: // valid: ends with 'throw' throw new Exception("unknown number"); case 3: message ~= "three "; break; case 4:

Re: request switch statement with common block

2013-08-05 Thread QAston
On Monday, 5 August 2013 at 09:37:11 UTC, dennis luehring wrote: this type of sub-branching "de-looping" is slow (if performance is relevant) and just not foreach-able, and so not functional-style programming - its called "for loop index micro management for unknown reasons" - but many program

Re: request switch statement with common block

2013-08-05 Thread Andre Artus
On Monday, 5 August 2013 at 11:32:14 UTC, QAston wrote: On Monday, 5 August 2013 at 09:37:11 UTC, dennis luehring wrote: this type of sub-branching "de-looping" is slow (if performance is relevant) and just not foreach-able, and so not functional-style programming - its called "for loop index

Re: request switch statement with common block

2013-08-05 Thread Andre Artus
Andre Artus: It may not always be the case, but in my experience this often leads to write-only code. I'm pretty new to D, so I'm not quite up to speed with the metaprogramming abilities, but I'm under the impression that this is what mixin's are for. MattCoder: Well I'm not experienced to

Re: request switch statement with common block

2013-08-05 Thread Andre Artus
On Monday, 5 August 2013 at 09:37:11 UTC, dennis luehring wrote: Am 05.08.2013 08:28, schrieb luminousone: or perhaps for( int i = 0 ; i < 10 ; i ++ ) in { assert( i == 0 ); } out { assert( i == 9 ); } body { ... stuff ... } that is just evil code if you got something todo befo

Re: request switch statement with common block

2013-08-05 Thread ron
On Monday, 5 August 2013 at 08:46:54 UTC, Andre Artus wrote: On Monday, 5 August 2013 at 06:28:12 UTC, luminousone wrote: perhaps a more generic solution should be looked at, extend contracts to work with all scope blocks. switch(somenumber) in { ... before stuff ... } out { after s

Re: request switch statement with common block

2013-08-05 Thread Borislav Kosharov
On Monday, 5 August 2013 at 19:58:21 UTC, ron wrote: On Monday, 5 August 2013 at 08:46:54 UTC, Andre Artus wrote: On Monday, 5 August 2013 at 06:28:12 UTC, luminousone wrote: perhaps a more generic solution should be looked at, extend contracts to work with all scope blocks. switch(somenumber

Re: request switch statement with common block

2013-08-05 Thread luminousone
On Monday, 5 August 2013 at 20:45:47 UTC, Borislav Kosharov wrote: On Monday, 5 August 2013 at 19:58:21 UTC, ron wrote: On Monday, 5 August 2013 at 08:46:54 UTC, Andre Artus wrote: On Monday, 5 August 2013 at 06:28:12 UTC, luminousone wrote: perhaps a more generic solution should be looked at,

Re: request switch statement with common block

2013-08-05 Thread Andre Artus
On Monday, 5 August 2013 at 19:58:21 UTC, ron wrote: On Monday, 5 August 2013 at 08:46:54 UTC, Andre Artus wrote: On Monday, 5 August 2013 at 06:28:12 UTC, luminousone wrote: perhaps a more generic solution should be looked at, extend contracts to work with all scope blocks. switch(somenumber

Re: request switch statement with common block

2013-08-05 Thread Andre Artus
Borislav Kosharov wrote: Speaking of contracts, and reading the docs I see: "Pre and Post Contracts The pre contracts specify the preconditions before a statement is executed. The most typical use of this would be in validating the parameters to a function. The post contracts validate the res

Re: request switch statement with common block

2013-08-05 Thread luminousone
On Monday, 5 August 2013 at 21:48:46 UTC, Andre Artus wrote: On Monday, 5 August 2013 at 19:58:21 UTC, ron wrote: On Monday, 5 August 2013 at 08:46:54 UTC, Andre Artus wrote: On Monday, 5 August 2013 at 06:28:12 UTC, luminousone wrote: perhaps a more generic solution should be looked at, extend

Re: request switch statement with common block

2013-08-05 Thread Andre Artus
As Andrei points out in his book ("The D Programming Language") contracts are not used to validate/scrub user (or any external) input as they can be compiled out of the executable. Contracts are there to check sanity at compile time, or at the very least during testing. The contract is (or

Re: request switch statement with common block

2013-08-05 Thread Andre Artus
On Saturday, 3 August 2013 at 19:22:53 UTC, Walter Bright wrote: On 8/3/2013 12:00 PM, JS wrote: What I really don't get it is why people think that just because they won't use such a feature then it must be useless to everyone else. You could provide supporting evidence by examining every us

Re: request switch statement with common block

2013-08-06 Thread QAston
I was under the impression that D has nested functions, unless by inner function you mean something else. Yeah, pardon my terminology.

Re: request switch statement with common block

2013-08-06 Thread Andre Artus
On Tuesday, 6 August 2013 at 07:44:46 UTC, QAston wrote: I was under the impression that D has nested functions, unless by inner function you mean something else. Yeah, pardon my terminology. Not an issue, they normally mean the same thing. I believe JS's use case can be covered easily and c