Names with trailing question mark

Jacob Carlborg doob at me.com
Mon Oct 3 23:49:46 PDT 2011


On 2011-10-04 03:13, Nick Sabalausky wrote:
> "bearophile"<bearophileHUGS at lycos.com>  wrote in message
> news:j6dgvp$1rot$1 at digitalmars.com...
>> Predicates are quite common. In D I presume the standard way to write them
>> is with a name like "isFoo". In other languages they are written in other
>> ways:
>>
>>
>> if (foo.isEven) {}
>> if (foo.isEven()) {}
>> filter!isEven(data)
>>
>> if (foo.evenQ) {}
>> if (foo.evenQ()) {}
>> filter!evenQ(data)
>>
>> if (foo.even?) {}
>> if (foo.even?()) {}
>> filter!even?(data)
>>
>> Other usages:
>>
>> contains?
>> areInside ==>  inside?
>>
>>
>
> It's nice, and it's one of the things in Ruby that I like, but I'd be
> surprised if it didn't cause parsing (or even lexing) ambiguities with ?:.
> If that could be reasonably solved, I'd be in favor of it, but I'm not sure
> it can.

If would choose to require a space before the question mark in a ternary 
operator.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list