Proposal: Extension Methods

Nick Sabalausky a at a.a
Sun May 18 11:38:55 PDT 2008


"Chris Wright" <dhasenan at gmail.com> wrote in message 
news:g0pcpm$14f2$1 at digitalmars.com...
> Nick Sabalausky wrote:
>> I was just looking through the documentation on some of the Phobos stuff 
>> that's new in D2, and at pipe! and compose! in particular. This is kind 
>> of nice (from docs):
>>
>> int[] a = pipe!(readText, split, map!(to!(int)))("file.txt");
>>
>> Not to nag about extension methods (well, ok, yes: to nag ;) ), but with 
>> extension methods (regardless if they're explicit or implicit), that 
>> could be cleaned up to:
>>
>> int[] a = "file.txt".readText().split().map!(to!(int)))();
>
> Or: auto a = "file.txt".readText.split.map!(to!(int)));
>
> Now, since "file.txt" is an array, readText returns an array, and split 
> returns an array, you can currently do this. Were any of those a class, 
> struct, or scalar, you'd be SOL until uniform call syntax is implemented.
>

Heh, true, I wasn't thinking about that example using all arrays. Bad 
example :)

Does eliminating the no-argument parentheses like that currently work, or 
are you proposing that?

> I wonder if uniform call syntax could be used the opposite way:
> class A
> {
> void foo(){}
> }
> foo(new A);

That's been my assumption. After all, isn't that what happens 
behind-the-scenes anyway (ie, "this" being passed as a hidden first 
parameter)? (I know it is in C++)

But, I wonder if disallowing that might eliminate some of the concerns I had 
about "uniform call syntax"/"implicit extension methods". I'll have to think 
about that.





More information about the Digitalmars-d mailing list