Thread overview | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 10, 2006 syntax idea: simplifed ifs | ||||
---|---|---|---|---|
| ||||
for example how often do we use constructs like if( x == 10 && x == 20 && x == 30 ) simplified: if( x == [10 && 20 && 30] ) if( a >= h && b >= h && c >= h ) simplified: if( [a && b && c] >= h ) (just an idea) ciao dennis |
April 10, 2006 Re: syntax idea: simplifed ifs | ||||
---|---|---|---|---|
| ||||
Posted in reply to dennis luehring | On Tue, 11 Apr 2006 08:04:21 +1000, dennis luehring <dl.soluz@gmx.net> wrote: > for example how often do we use constructs like > > if( x == 10 && x == 20 && x == 30 ) > > simplified: > if( x == [10 && 20 && 30] ) > > if( a >= h && b >= h && c >= h ) > > simplified: > if( [a && b && c] >= h ) > > (just an idea) A good one too, in my opinion. The || symbol would also be useful. if ( [a || b || c] >= h ) -- Derek Parnell Melbourne, Australia |
April 10, 2006 Re: syntax idea: simplifed ifs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote:
> On Tue, 11 Apr 2006 08:04:21 +1000, dennis luehring <dl.soluz@gmx.net> wrote:
>
>> for example how often do we use constructs like
>>
>> if( x == 10 && x == 20 && x == 30 )
>>
>> simplified:
>> if( x == [10 && 20 && 30] )
>>
>> if( a >= h && b >= h && c >= h )
>>
>> simplified:
>> if( [a && b && c] >= h )
>>
>> (just an idea)
>
>
> A good one too, in my opinion. The || symbol would also be useful.
>
> if ( [a || b || c] >= h )
or think of
if( [a || b || c ] >= [ h && b ] )
|
April 10, 2006 Re: syntax idea: simplifed ifs | ||||
---|---|---|---|---|
| ||||
Posted in reply to dennis luehring | "dennis luehring" <dl.soluz@gmx.net> wrote in message news:e1ekp6$jr7$1@digitaldaemon.com... > for example how often do we use constructs like > > if( x == 10 && x == 20 && x == 30 ) > > simplified: > if( x == [10 && 20 && 30] ) > > if( a >= h && b >= h && c >= h ) > > simplified: > if( [a && b && c] >= h ) > > (just an idea) > > ciao dennis Considering that you can't have multiple assignments to a variable, if you had that many possible OR conditions,, couldn't you just use a combined switch like so: switch(x) { case 10: case 20: case 30: ... default: break; } This still leaves open the issue of multiple variables though; what you suggest may work. |
April 11, 2006 Re: syntax idea: simplifed ifs | ||||
---|---|---|---|---|
| ||||
Posted in reply to dennis luehring | On Tue, 11 Apr 2006 00:24:14 +0200, dennis luehring wrote: > Derek Parnell wrote: >> On Tue, 11 Apr 2006 08:04:21 +1000, dennis luehring <dl.soluz@gmx.net> wrote: >> >>> for example how often do we use constructs like >>> >>> if( x == 10 && x == 20 && x == 30 ) >>> >>> simplified: >>> if( x == [10 && 20 && 30] ) >>> >>> if( a >= h && b >= h && c >= h ) >>> >>> simplified: >>> if( [a && b && c] >= h ) >>> >>> (just an idea) >> >> A good one too, in my opinion. The || symbol would also be useful. >> >> if ( [a || b || c] >= h ) > > or think of > > if( [a || b || c ] >= [ h && b ] ) Not sure what that would mean ... is it ... if ( (a >= h || b >= h || c => h) && ((a >= b || b >= b || c => b))) OR if ( (a >= h && a >= b) || (b => h && b >= b) || (c => h && c >= b) ) I think the idea should be kept at one '[...]' group only and one of '&&','||' per group ( that is ... don't mix && and || inside the [] ). -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocracy!" 11/04/2006 9:57:47 AM |
April 11, 2006 Re: syntax idea: simplifed ifs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ameer Armaly | On Mon, 10 Apr 2006 19:18:55 -0400, Ameer Armaly wrote: > "dennis luehring" <dl.soluz@gmx.net> wrote in message news:e1ekp6$jr7$1@digitaldaemon.com... >> for example how often do we use constructs like >> >> if( x == 10 && x == 20 && x == 30 ) >> >> simplified: >> if( x == [10 && 20 && 30] ) >> >> if( a >= h && b >= h && c >= h ) >> >> simplified: >> if( [a && b && c] >= h ) >> >> (just an idea) >> >> ciao dennis > Considering that you can't have multiple assignments to a variable, if you had that many possible OR conditions,, couldn't you just use a combined switch like so: > > switch(x) > { > case 10: > case 20: > case 30: > ... > default: > break; > } > This still leaves open the issue of multiple variables though; what you > suggest may work. The problem with 'switch' is it requires literals or consts. One can't do ... switch (h) { case a: case b: case c: ... break; default: break; } -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocracy!" 11/04/2006 10:01:40 AM |
April 11, 2006 Re: syntax idea: simplifed ifs | ||||
---|---|---|---|---|
| ||||
Posted in reply to dennis luehring | dennis luehring wrote:
> for example how often do we use constructs like
>
> if( x == 10 && x == 20 && x == 30 )
>
> simplified:
> if( x == [10 && 20 && 30] )
>
> if( a >= h && b >= h && c >= h )
>
> simplified:
> if( [a && b && c] >= h )
>
> (just an idea)
>
> ciao dennis
I've always wanted something like this!!!! but I think the proposed syntax might not fit very well with the D grammar.
hmm, come to think of it, maybe it can already be implemented with templates.
so,
if( x == 10 || x == 20 || x == 30 )
becomes:
if( equals!(x).anyOf( 10, 20, 30 ) )
or something like that!
any template guru up to it?
On a side note: the expression( x == 10 && x == 20 && x == 30 ) is rediclious, it's always false ;)
|
April 11, 2006 Re: syntax idea: simplifed ifs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hasan Aljudy | On Mon, 10 Apr 2006 18:03:57 -0600, Hasan Aljudy wrote: > dennis luehring wrote: >> for example how often do we use constructs like >> >> if( x == 10 && x == 20 && x == 30 ) >> >> simplified: >> if( x == [10 && 20 && 30] ) >> >> if( a >= h && b >= h && c >= h ) >> >> simplified: >> if( [a && b && c] >= h ) >> >> (just an idea) >> >> ciao dennis > > I've always wanted something like this!!!! but I think the proposed syntax might not fit very well with the D grammar. > > hmm, come to think of it, maybe it can already be implemented with templates. > > so, > > if( x == 10 || x == 20 || x == 30 ) > > becomes: > if( equals!(x).anyOf( 10, 20, 30 ) ) > > or something like that! > > any template guru up to it? > > On a side note: the expression( x == 10 && x == 20 && x == 30 ) is rediclious, it's always false ;) Try not using literals ... ;-) The expression( x == a && x == b && x == c ) is not always false. -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocracy!" 11/04/2006 10:15:53 AM |
April 11, 2006 Re: syntax idea: simplifed ifs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | "Derek Parnell" <derek@psych.ward> wrote in message news:noyfbcyf3t01$.m2gl86mb13se.dlg@40tude.net... > On Mon, 10 Apr 2006 19:18:55 -0400, Ameer Armaly wrote: > >> "dennis luehring" <dl.soluz@gmx.net> wrote in message news:e1ekp6$jr7$1@digitaldaemon.com... >>> for example how often do we use constructs like >>> >>> if( x == 10 && x == 20 && x == 30 ) >>> >>> simplified: >>> if( x == [10 && 20 && 30] ) >>> >>> if( a >= h && b >= h && c >= h ) >>> >>> simplified: >>> if( [a && b && c] >= h ) >>> >>> (just an idea) >>> >>> ciao dennis >> Considering that you can't have multiple assignments to a variable, if >> you >> had that many possible OR conditions,, couldn't you just use a combined >> switch like so: >> >> switch(x) >> { >> case 10: >> case 20: >> case 30: >> ... >> default: >> break; >> } >> This still leaves open the issue of multiple variables though; what you >> suggest may work. > > The problem with 'switch' is it requires literals or consts. One can't do ... > > switch (h) > { > case a: > case b: > case c: > ... > break; > default: break; > } > That's true. In such a case I think that the above proposal might work, or perhaps the templates that Hasan suggested. > -- > Derek > (skype: derek.j.parnell) > Melbourne, Australia > "Down with mediocracy!" > 11/04/2006 10:01:40 AM |
April 11, 2006 Re: syntax idea: simplifed ifs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hasan Aljudy | > I've always wanted something like this!!!! but I think the proposed syntax might not fit very well with the D grammar. another idea > hmm, come to think of it, maybe it can already be implemented with templates. oh no! what we need is more syntactic sugar - not another boost library (hell) :-) > so, > > if( x == 10 || x == 20 || x == 30 ) > > becomes: > if( equals!(x).anyOf( 10, 20, 30 ) ) > > or something like that! > > any template guru up to it? > > On a side note: the expression( x == 10 && x == 20 && x == 30 ) is rediclious, it's always false ;) example version 2: if( x == a && x == b && x == c ) => if( x == [a && b && c] ) --> or maybe even "if( x == [a,b,c](&&))" but this goes a little bit to fast into the "how can we integrate vector stuff" direction... ciao dennis |
Copyright © 1999-2021 by the D Language Foundation