Jump to page: 1 24  
Page
Thread overview
What about some standard mixins
May 26, 2004
J Anderson
May 26, 2004
Matthew
May 26, 2004
Walter
May 26, 2004
Matthew
May 26, 2004
J Anderson
May 26, 2004
Norbert Nemec
May 27, 2004
J Anderson
May 27, 2004
Norbert Nemec
May 27, 2004
J Anderson
May 27, 2004
Norbert Nemec
May 27, 2004
Antti Sykäri
May 28, 2004
Norbert Nemec
May 27, 2004
Ivan Senji
May 26, 2004
Roberto Mariottini
May 26, 2004
J Anderson
May 26, 2004
Kevin Bealer
May 26, 2004
Norbert Nemec
May 26, 2004
Kris
May 26, 2004
Norbert Nemec
May 26, 2004
Kris
May 26, 2004
Norbert Nemec
May 26, 2004
Kris
May 26, 2004
Kevin Bealer
May 26, 2004
Sean Kelly
May 27, 2004
Kevin Bealer
May 27, 2004
Ivan Senji
May 27, 2004
Kevin Bealer
May 27, 2004
Kevin Bealer
May 27, 2004
Kris
May 27, 2004
Kevin Bealer
May 27, 2004
Kris
May 31, 2004
Bent Rasmussen
May 26, 2004
Andy Friesen
Re: What about some standard mixins (for common operator-collections)
May 26, 2004
davepermen
Jun 02, 2004
Walter
Jun 03, 2004
davepermen
Jun 06, 2004
J Anderson
Jun 06, 2004
davepermen
May 26, 2004
Just a though, what if we had some standard mixins in one of the standard libraries.  I mean for thing like vectors you generally write up the same code.  Something like:

template arrayMixin(structName, type, value)
{
    type opIndex(int i) { ... }
...ect...
}

Then in your own module you could write:

struct myArray(type)
{
     arrayMixin!(myArray, type, values); //Note that I don't think values will work ATM.

     type [] values;

}

Then you could overload any functions you wish to change.   I'm sure there are heaps of these types of common method groups.

It would be really helpful for lazy programmers like me.

I should add that this is basicly what classes are meant to do but for things like vectors you want a "light-class" which happens to be a struct in D.  I guess there could be a class version as well.

-- 
-Anderson: http://badmama.com.au/~anderson/
May 26, 2004
There'll be some standard ones in DTL, although they'll necessarily pertain to containers.

As a general point, I'm still a little nervous about the potential ubituity of mixins, as supported by their current implementation, but I guess we'll just have to suck it and see.

"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:c90q9p$2t6k$3@digitaldaemon.com...
> Just a though, what if we had some standard mixins in one of the standard libraries.  I mean for thing like vectors you generally write up the same code.  Something like:
>
> template arrayMixin(structName, type, value)
> {
>      type opIndex(int i) { ... }
> ...ect...
> }
>
> Then in your own module you could write:
>
> struct myArray(type)
> {
>       arrayMixin!(myArray, type, values); //Note that I don't think
> values will work ATM.
>
>       type [] values;
>
> }
>
> Then you could overload any functions you wish to change.   I'm sure there are heaps of these types of common method groups.
>
> It would be really helpful for lazy programmers like me.
>
> I should add that this is basicly what classes are meant to do but for things like vectors you want a "light-class" which happens to be a struct in D.  I guess there could be a class version as well.
>
> -- 
> -Anderson: http://badmama.com.au/~anderson/


May 26, 2004
J Anderson wrote:

>
> I should add that this is basicly what classes are meant to do but for things like vectors you want a "light-class" which happens to be a struct in D.  I guess there could be a class version as well.


And a class version could easily be done like:

class vector(type)
{
arrayMixin!(vector, type, values);
...
}

So I guess there wouldn't be any redundancy problems.


-- 
-Anderson: http://badmama.com.au/~anderson/
May 26, 2004
"Matthew" <matthew.hat@stlsoft.dot.org> wrote in message news:c90ql8$2u1r$1@digitaldaemon.com...
> As a general point, I'm still a little nervous about the potential
ubituity of
> mixins, as supported by their current implementation, but I guess we'll
just have
> to suck it and see.

?


May 26, 2004
Nothing specific. Just a feeling at the moment.

Sorry to be vague.

"Walter" <newshound@digitalmars.com> wrote in message news:c910ga$4fc$1@digitaldaemon.com...
>
> "Matthew" <matthew.hat@stlsoft.dot.org> wrote in message news:c90ql8$2u1r$1@digitaldaemon.com...
> > As a general point, I'm still a little nervous about the potential
> ubituity of
> > mixins, as supported by their current implementation, but I guess we'll
> just have
> > to suck it and see.
>
> ?
>
>


May 26, 2004
In article <c910ga$4fc$1@digitaldaemon.com>, Walter says...
>
>"Matthew" <matthew.hat@stlsoft.dot.org> wrote in message news:c90ql8$2u1r$1@digitaldaemon.com...
>> As a general point, I'm still a little nervous about the potential
>ubituity of
>> mixins, as supported by their current implementation, but I guess we'll
>just have
>> to suck it and see.
>
> ?

I can add what I've thought when I've just finished to read the mixins specification: mixins are something I just don't want to need to use. But if I'll need them I'll use them without worring.

I remember that I felt the same when I first read about templates.

Maybe we just have to wait to be used to them, first.

Ciao

PS: I dont' know if this is standard english. Maybe I've used some proprietary extensions...


May 26, 2004
Matthew wrote:

>Nothing specific. Just a feeling at the moment.
>
>Sorry to be vague.
>  
>
I've the same kinda feeling.  It feels like macros with a different syntax.  I mean essentially a mixin is a copy/paste tool.

-- 
-Anderson: http://badmama.com.au/~anderson/
May 26, 2004
J Anderson wrote:

> Matthew wrote:
> 
>>Nothing specific. Just a feeling at the moment.
>>
>>Sorry to be vague.
>> 
>>
> I've the same kinda feeling.  It feels like macros with a different syntax.  I mean essentially a mixin is a copy/paste tool.

So are templates. So what?

D has a powerful compile-time meta-language. The purpose of this meta-language is to do all kinds of copy-and-paste operations before the real compilation is started.

Unlike the CPP, this source-code processing cannot by fully split out of the compiling process. Unlike CPP, it uses the same namespace as the compiler, but it offers most of the power of the CPP.

C++ had two steps of "preprocessing": first the CPP, then the template instatiation (which is basically lots of copy-and-paste as well) then the real compilation.

Mixins basically *are* macros with a different syntax. But through that syntax, they are far better integrated into the language itself then CPP-macros ever were.

May 26, 2004
In article <c90q9p$2t6k$3@digitaldaemon.com>, J Anderson says...
>
>Just a though, what if we had some standard mixins in one of the standard libraries.  I mean for thing like vectors you generally write up the same code.  Something like:
>
>template arrayMixin(structName, type, value)
>{
>     type opIndex(int i) { ... }
>...ect...
>}
>
>Then in your own module you could write:
>
>struct myArray(type)
>{
>      arrayMixin!(myArray, type, values); //Note that I don't think
>values will work ATM.
>
>      type [] values;
>
>}

I think this can work, but I think "values" has to be part of the mixin.  I don't think a mixin can refer to other stuff "near it" in the class.  The class can see into the mixin, but not the other way.

Which you can do with a macro of course; you can use the variable "i" in a macro and it will "pick up" a local variable with that name.  This is kind of like the coming-from-basic programmers who create a global "int i" so they don't need to type "int" everywhere.

Kevin



May 26, 2004
Kevin Bealer wrote:

> In article <c90q9p$2t6k$3@digitaldaemon.com>, J Anderson says...
>>
>>Just a though, what if we had some standard mixins in one of the standard libraries.  I mean for thing like vectors you generally write up the same code.  Something like:
>>
>>template arrayMixin(structName, type, value)
>>{
>>     type opIndex(int i) { ... }
>>...ect...
>>}
>>
>>Then in your own module you could write:
>>
>>struct myArray(type)
>>{
>>      arrayMixin!(myArray, type, values); //Note that I don't think
>>values will work ATM.
>>
>>      type [] values;
>>
>>}
> 
> I think this can work, but I think "values" has to be part of the mixin.
> I
> don't think a mixin can refer to other stuff "near it" in the class.  The
> class can see into the mixin, but not the other way.

Why that? There even is an example in the specs that does just that:

-----------------------
 Mixins can parameterize symbols using alias parameters:
        template Foo(alias b)
        {
            int abc() { return b; }
        }

        void test()
        {
            int y = 8;
            mixin Foo!(y);
            assert(abc() == 8);
        }
------------------------


« First   ‹ Prev
1 2 3 4