property syntax strawman

Steven Schveighoffer schveiguy at yahoo.com
Mon Aug 3 08:06:53 PDT 2009


On Mon, 03 Aug 2009 10:45:10 -0400, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> Michiel Helvensteijn wrote:
>> Andrei Alexandrescu wrote:
>>
>>>> auto data = std.file.readText(filename).chomp.split;
>>> I love that too. Unfortunately, the way the water is moving, it looks
>>> like we'll lose some or all of that.
>>  That's not really true. Some of those no-parameter functions are just  
>> meant
>> to be read-only properties instead of functions.
>>  auto data = std.file.textFrom(filename).chomped.split;
>
> Sure you meant:
>
> auto data = std.file.textFrom(filename).chomped.splat;

This brings up a good point.  split is one of those rare words where split  
without parens and split() with parens mean exactly the same thing.

That is, split as a property is an adjective, meaning "give me this data  
in a split form" , and as an adjective, split means "split this data", the  
result of which is the split data.

So split maybe is one word that is an exception -- it's meaning is clear  
for both a property and a function, AND the implied meaning is the same  
for both.

I don't think this means we should take this one exception to invalidate  
the whole idea of separating function from property, but maybe there could  
be ways to annotate such functions as callable both ways.  I'm sure the  
number of functions that have this property is few such that the pain of  
annotating "call this both ways" is minimial.  Or else, allow defining a  
property and a function with the same name (*gulp*).

One thing is for certain -- I'd rather have to deal with this quandry as  
an author of code than deal with the ambiguity of the current design as a  
user of code.

---------

I just thought of another issue with property definitions.  How do you  
declare a property of an array?  Today it's:

char[] chomped(char[] input);

Note that any getter property contains an argument which is the object  
you're calling the property on (normally implied because the definition is  
inside an aggregate definition).  But with arrays it's explicit.

So how does this fit in Walter's proposed syntax?

char[] chomped {...}

Where does the input go?

-Steve



More information about the Digitalmars-d mailing list