Either I'm just too stupid, or D is lacking something

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Sat Jul 29 09:36:12 PDT 2006


Oskar Linde wrote:
> Oskar Linde skrev:
>> Wolfgang Draxinger skrev:
>>> Oskar Linde wrote:
>>>
>>>> It is a minor change, but would break existing code, so getting
>>>> it before 1.0 would be preferred.
>>>
>>> Could you give me an example of breakage? I don't see a reason
>>> (yet), why that would break something. I'd have said, that my
>>> suggestion is a superset of the old behaviour and backwards
>>> compatible, but seem's I was wrong.
>>
>> Currently, when a template contains several functions, they are not 
>> implicit template properties and must be called as func!().func(...). 
>> If the proposed change was introduced, they would be required to be 
>> called as func!()(...). Example:
> 
> Another proposal that I made before in conjunction with the above is to 
> make implicit template properties explicit via the /this/ keyword. It 
> would work analogous to how /this/ is used to denote class constructors.
> 
> template myfunc(T) {
>     T this() {...}
>     T this(int x) {...}
>     T this(double x) {...}
> }
> 
> and:
> 
> template IsSomethingOrWhatever(T) {
>     const this = ...;
> }
> 
> The advantages would be that implicit template properties would become 
> explicit. It would in many cases save some typing and leave only one 
> instead of two places to update when a template is renamed. The somewhat 
> dubious rule of special handling when the template and template member 
> name are the same could be removed.
> 
> One could also imagine private template members in conjunction with 
> implicit template properties. Something that isn't possible today:
> 
> template myfync(T) {
>     private alias Something!(T) SomeType;
> 
>     SomeType this() { ... }
>     SomeType this(int x) { ... }
>     SomeType this(double x) { ... }
> }
> 
> which would both improve readability and save typing. Not only for the 
> case with several polymorphic template functions:
> 
> template foo(T1,T2) {
>     private alias ALongExpression!(Involving!(T1).and!(T2)) RetType;
> 
>     RetType this(T1 a, T2 b) {
>         RetType ret;
>         ...
>         return ret;
>     }
> }
> 
> With todays templates, the above becomes less readable.
> 
> /this/ would be shadowed by locally defined classes, just like /this/ 
> currently gets shadowed by inner classes.
> 
> /Oskar
> 

Seems like a nice idea, although I would prefer a keyword other than 
"this", even if a new one, like "thisalias" or something. I'd like to 
think of "this" as always referring to some kind of runtime instance.

-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list