Is @property implementable?
Jonathan M Davis
jmdavisProg at gmx.com
Wed Mar 2 14:14:30 PST 2011
On Wednesday, March 02, 2011 13:49:40 Michel Fortin wrote:
> Consider that currently, using an array as a range is implemented this way:
>
> int front(int[] array) {
> return array[0];
> }
>
> int[] array = [1,2,3];
> auto e = array.front;
>
> Currently, this work fine because the compiler treats "array.front" and
> "array.front()" as the same thing, they're both rewritten as
> "front(array)".
>
> Now consider the world of the future where only functions marked with
> @property can use the property syntax, and only functions *not* marked
> with @property can use the function call syntax. Now, for "array.front"
> to work you'd have to label "front" with @property, like this:
>
> @property int front(int[] array) {
> return array[0];
> }
>
> The problem is that now, for "array.front" to work it'd have to be
> rewritten as "front = array", which does not make any sense.
>
> So what to do? And also, what happens if you want to implement a setter
> for "array.front = 1"?
I would expect the compiler to be smart enough to combine the fact that you can
call functions on arrays as if they were member functions and @property to allow
you to deal with any property as if it were a member of the array. So, the fact
that the property is declared external to the array should be irrelevant. It
should work just the same as any property would on a user-defined type.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list