struct inheritance
Jari-Matti Mäkelä
jmjmak at utu.fi.invalid
Fri Aug 31 12:26:51 PDT 2007
Bill Baxter wrote:
> Don Clugston wrote:
>> Reiner Pope wrote:
>>> Bill Baxter wrote:
>>>> Let us all turn our copies of WalterAndrei.pdf to page 40 where yea
>>>> verily it doth say:
>>>>
>>>> struct M { int a; }
>>>> struct S {
>>>> M m;
>>>> alias m this;
>>>> int b;
>>>> }
>>>>
>>>> Why not just allow mixin to do this?
>>>>
>>>> struct M { int a; }
>>>> struct S {
>>>> mixin M;
>>>> int b;
>>>> }
>>>>
>>>> That's basically the way it's done now except now it would be more
>>>> like: template MMixin() { int a; }
>>>> struct M { mixin M; }
>>>> struct S { mixin M; int b; }
>>>>
>>>> Just let us treat a struct like a zero arg template for mixin purposes.
>>>>
>>>> --bb
>>>
>>> Template mixins require that the sourcecode of the template is
>>> available to the compiler. Aliases don't. In this sense at least,
>>> aliases are cleaner.
> >> -- Reiner
>
> Just to be clear -- I'm not saying the 'mixin M' should be a shortcut
> for the similar-looking template mixin. Just suggesting to reuse the
> keyword for a similar concept. You want to add in the members of
> another struct and at the same time avoid it looking like polymorphic
> inheritance.
I like it. It's also more consistent with the previous behavior.
>> Also, Walter wants to get [rid] of template mixins. (That was discussed a
>> little on the Saturday).
>
> Now that's interesting. Replaced by macros?
Sounds really hilarious since I've always considered mixins to be macros in
D. If you look at the new paper, the only differences between 'macro' and
template+mixin are
a) mixins provide only unhygienic macros, 'macro' has syntax for both cases
b) template mixins can only inject declarations
c) parameter types and pattern matching
What I would like to see is an unification of macros and templates. I don't
see any reason why templates cannot have better pattern matching or
hygienic invocations. It should be pretty easy to copy that functionality
from one's favourite state of the art purely functional language.
Hmm, one more thing. The slides only show how pattern matching works with
expressions. What about blocks of code? Will it be possible to implement a
custom <insert some builtin statement here> with macros? Will all
statements in D 2.0 become expressions?
More information about the Digitalmars-d
mailing list