Function calls

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Jan 28 14:10:32 PST 2010


Andrei Alexandrescu wrote:
> Don wrote:
>> I think there are 3 cases:
>> (1) I want this to _always_ be treated as if it were a field;
>> (2) I want this to _always_ be treated as a function;
>> (3) I don't care. (this arises most frequently in generic code: you're 
>> forced to choose between a field and a function, but you can't have 
>> both).
>>
>> D1 caters for case (3) very well, but does extremely poorly for (1) 
>> and (2).
>> @property is perfect for case (1). It also seems reasonable to 
>> disallow property assignment syntax for anything which isn't marked as 
>> @property.
>>
>> Disallowing removable parentheses for no-parameter functions is the 
>> contentious part.
> 
> Good summary. I now wonder, could one overload based on @property?
> 
> auto a = container.empty; // check for emptiness
> container.empty();        // take the trash out
> 
> !
> 
> Anyway, I have one more comment about the example:
> 
> foreach (line; stdio.byLine) { ... }
> vs.
> foreach (line; stdio.byLine()) { ... }
> 
> Steve said, byLine fetches a range off stdio. In fact it's not - it's an 
> opApply() based loop.

I was mistaken. byLine does fetch a range.

http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/stdio.d

BTW I love byLine.


Andrei



More information about the Digitalmars-d mailing list