syntax idea: simplifed ifs

Hasan Aljudy hasan.aljudy at gmail.com
Thu Apr 13 18:58:11 PDT 2006


Bruno Medeiros wrote:
> 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
> 
> 

Sure you can do them with functions, it just adds a bit of unnecessary 
overhead.

I don't usually care much if a nice structure/design adds a small 
runtime overhead, but I noticed that alot of D'ers do care, so that's 
why I pospsed a templated solution.



More information about the Digitalmars-d mailing list