feature req: extend property syntax func calls to classes, interfaces, primitives? also, final interface methods w. code

David B. Held dheld at codelogicconsulting.com
Mon May 21 22:54:43 PDT 2007


Downs wrote:
> [...]
> 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; "

This is related to a proposal to allow both member and free function 
call syntax.  That is:

a.foo();

could also be called as:

foo(a);

The main problem with this feature is that it severely complicates the 
lookup rules, and Walter doesn't want D to end up in the morass of C++'s 
ADL and namespace hell.  However, Scala has it, and generics really 
needs it (and Andrei strongly favors it), so there's a fighting chance 
that it will make it into the language.

> [...]
>  >  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.
> [...]

I don't know that Walter will allow method bodies in interfaces, but if 
the free/member proposal goes through, you can achieve it by simply 
writing the second form to get the effect of the first.  Since access 
scope is module-private, as long as the interface is in the same module, 
it will have access.  Is that good enough?

Dave



More information about the Digitalmars-d mailing list