feature req: extend property syntax func calls to classes, interfaces, primitives? also, final interface methods w. code
Downs
default_357-line at yahoo.de
Mon May 21 19:40:45 PDT 2007
It is my understanding that the current method of calling functions on arrays was first introduced accidentally.
The largely positive reaction this change has received in the D community warrants,
in my (admittedly nsh) opinion, a look at extending the same kind of syntax to types other than arrays.
This proposal has two parts, the second of which builds upon the first.
1) to extend the property syntax to classes and interfaces, _maybe_ even arrays and primitive types.
Such a change would allow one to write "interface barf { } void test(barf b) { do stuff; } myBarf.test; "
Should this proposal be implemented, it would also become possible to
2) allow interfaces to contain actual methods, bringing them closer to abstract classes.
I am not talking of Multiple Inheritance, as the resulting methods would not reside in the vtable.
Instead, an interface of the form
> interface test { void MethodWithCode() { /* do stuff */ } }
would be equivalent to writing
> interface test { } void MethodWithCode(test hiddenref) { with (hiddenref) { /* do stuff */ } }
with the exception of access to private class members.
In that sense, the function would always be final.
In the case of a class deriving from multiple interfaces which include the same method
signature, this would not present an ambiguity, but a syntax error, as the following
(currently working) example shows:
> interface foo { } interface bar { }
> class whee : foo, bar { }
>
> void test(foo fee) { } void test(bar bee) { }
> void main() { test(new whee); }
> test57.d:5: function test57.test called with argument types:
> (whee)
> matches both:
> test57.test(foo)
> and:
> test57.test(bar)
What do you think?
-- downs
More information about the Digitalmars-d
mailing list