syntax idea: simplifed ifs

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Thu Apr 13 12:58:54 PDT 2006


Derek Parnell wrote:
> 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 ... ;-)
> 
In the template example? Why did both of you think a template was 
necessary? One can do this with plain old functions. Well, with typesafe 
variadic functions that is:
   equalsAny( x + y, 10, b, c)
also possible (but somewhat weird..) :
   equals(x + y).AnyOf(10, b, c)

Or am I missing something terribly obvious? :o


-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list