Proposal request: explicit propreties

naryl cy at ngs.ru
Tue Apr 1 13:12:09 PDT 2008


On Tue, 01 Apr 2008 23:39:10 +0400, Bill Baxter  
<dnewsgroup at billbaxter.com> wrote:

> Steven Schveighoffer wrote:
>> "Bill Baxter" wrote
>>> I've also run across cases where the compiler fails to realize it  
>>> should call a property method unless you explicitly put the () after  
>>> it.  I can't recall exactly where.  That's just a bug, but it is  
>>> something to consider.
>>  It's when the object being returned by a property overloads opCall.   
>> The prime example I know is tango's Stdout.newline():
>>  Stdout("hello").newline()("world").newline;
>>  If you don't include the extra (), then the compiler thinks you're  
>> calling newline("world");
>>  This is one case where the nature of D properties is exploited in a  
>> way that would be unnatural with explicit properties.  newline is  
>> clearly not a property, but using it in this way is pretty clear (and  
>> convenient).
>
> No, that's not the one I was thinking of.  I have seen cases where the  
> terminal () was required.  Next time I run into it I'll try to make a  
> repro.
>
> --bb

The other case is when you call an array property like  
tango.core.Array.popHeap.

   1 import tango.core.Array;
   2
   3 void main() {
   4     int[] a = ([1, 3, 2, 5, 4].dup);
   5     a.popHeap();	//Doesn't compiles without terminal ()
   6 }



More information about the Digitalmars-d mailing list