January 03, 2004
Most excellent!  See, Walter *does* listen to us.  ;)  It's not implicit instantiation, but it's better than it was.  It seems this syntax won't conflict with use of ! as logical not.

I noticed a doc bug (I think),  in typeof section:

int[typeof[p]] a;	// a is of type int[int*]

Shouldn't that be typeof(p)?

Multiple case expressions are good.  Adding goto case opens the door for later removing implicit fallthru (D 2.0?) so I see that as good also.

Walter, do you see the template "limitations" being lifted in the future?

Since there were conflicts between std.intrinsic and std.math fixed, I will try my D3D test again using 0.77.. thanks!

Sean

"Walter" <walter@digitalmars.com> wrote in message news:bt5esp$1o8d$1@digitaldaemon.com...
> Lots of new additions. Didn't get to most of the bug reports; I wanted to get D to be 'feature complete' first, the next version will be bug polishing. I'm setting sights on releasing D 1.0 by March.
>
> Lots of improvements to templates:
>
> o    No more instance keyword (though still supported for the time being).
> To instantiate template Foo with arguments a,b use:
>     Foo!(a,b)
> which is equivalent to the C++:
>     Foo<a,b>
> but doesn't have parsing problems.
>
> o If there's only one declaration in a template, and its name matches the template name, it is 'promoted' to the enclosing scope:
>
>     template Foo(T) { class Foo { T a,b; }}
>     ...
>     void func()
>     {
>         Foo(int) x;
>         x.a = 3;
>     }
>
> o As a shortcut to the above, the template could have been written as:
>
>     class Foo(T) { T a,b; }
>
> There is no equivalent shortcut for function templates, the syntax would look too awful. But this works:
>
>     template Max(T) { T Max(T a, T b) { return ... ; } }
>     ...
>         x = Max!(int)(5,7);
>
> o Templates can now take 'alias' parameters where any non-local symbol can be substituted:
>
>     template Foo(alias S) { int* x = &S; }
>
> See the changelog for more cool stuff:
>
> http://www.digitalmars.com/d/changelog.html
>
>
>


January 03, 2004
This module causes an internal error "Internal error: e2ir.c 133":   (I'm also having trouble with it not thinking dim and tfloat are defined in some other methods... still trying to track that down)

module vector;

import std.intrinsic;

import std.math;

public:

template VecTemplate(tfloat, int dim)

{

struct Vector

{

tfloat d[dim];

Vector opMul(tfloat b) { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[i] *
b; return r; }

Vector opDiv(tfloat b) { return *this * (1/b); }

tfloat opMul(Vector b) { tfloat r=0; for (int i=0; i<dim; ++i) r += d[i];
return r; }

}

tfloat sqr(Vector v)

{

return v * v;

}

tfloat abs(Vector v)

{

return sqrt(sqr(v));

}

}

alias VecTemplate!(float,2) V2;

alias V2.Vector Vector2;

unittest

{

float n;

Vector2 a,b,c;

n = V2.sqr(a);

n = V2.abs(a);

n = V2.abs(b-a);

}



I'm not sure what to do about template methods sqr, abs, etc, as their namespace must be explicitly indicated... what I have above (V2 alias) is the most elegant solution I thought of so far.

I think foreach has the potential to really clean up the implementation of this Vector template, and if I give it an opApply it will help users out too.

Sean

"Walter" <walter@digitalmars.com> wrote in message news:bt5esp$1o8d$1@digitaldaemon.com...
> Lots of new additions. Didn't get to most of the bug reports; I wanted to get D to be 'feature complete' first, the next version will be bug polishing. I'm setting sights on releasing D 1.0 by March.
>
> Lots of improvements to templates:
>
> o    No more instance keyword (though still supported for the time being).
> To instantiate template Foo with arguments a,b use:
>     Foo!(a,b)
> which is equivalent to the C++:
>     Foo<a,b>
> but doesn't have parsing problems.
>
> o If there's only one declaration in a template, and its name matches the template name, it is 'promoted' to the enclosing scope:
>
>     template Foo(T) { class Foo { T a,b; }}
>     ...
>     void func()
>     {
>         Foo(int) x;
>         x.a = 3;
>     }
>
> o As a shortcut to the above, the template could have been written as:
>
>     class Foo(T) { T a,b; }
>
> There is no equivalent shortcut for function templates, the syntax would look too awful. But this works:
>
>     template Max(T) { T Max(T a, T b) { return ... ; } }
>     ...
>         x = Max!(int)(5,7);
>
> o Templates can now take 'alias' parameters where any non-local symbol can be substituted:
>
>     template Foo(alias S) { int* x = &S; }
>
> See the changelog for more cool stuff:
>
> http://www.digitalmars.com/d/changelog.html
>
>
>


January 03, 2004
Are your writing several collection classes ?  If so can you post when your done ?

C


"Sean L. Palmer" <palmer.sean@verizon.net> wrote in message news:bt7cbt$1k9n$1@digitaldaemon.com...
> This module causes an internal error "Internal error: e2ir.c 133":   (I'm also having trouble with it not thinking dim and tfloat are defined in
some
> other methods... still trying to track that down)
>
> module vector;
>
> import std.intrinsic;
>
> import std.math;
>
> public:
>
> template VecTemplate(tfloat, int dim)
>
> {
>
> struct Vector
>
> {
>
> tfloat d[dim];
>
> Vector opMul(tfloat b) { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[i]
*
> b; return r; }
>
> Vector opDiv(tfloat b) { return *this * (1/b); }
>
> tfloat opMul(Vector b) { tfloat r=0; for (int i=0; i<dim; ++i) r += d[i];
> return r; }
>
> }
>
> tfloat sqr(Vector v)
>
> {
>
> return v * v;
>
> }
>
> tfloat abs(Vector v)
>
> {
>
> return sqrt(sqr(v));
>
> }
>
> }
>
> alias VecTemplate!(float,2) V2;
>
> alias V2.Vector Vector2;
>
> unittest
>
> {
>
> float n;
>
> Vector2 a,b,c;
>
> n = V2.sqr(a);
>
> n = V2.abs(a);
>
> n = V2.abs(b-a);
>
> }
>
>
>
> I'm not sure what to do about template methods sqr, abs, etc, as their namespace must be explicitly indicated... what I have above (V2 alias) is the most elegant solution I thought of so far.
>
> I think foreach has the potential to really clean up the implementation of this Vector template, and if I give it an opApply it will help users out too.
>
> Sean
>
> "Walter" <walter@digitalmars.com> wrote in message news:bt5esp$1o8d$1@digitaldaemon.com...
> > Lots of new additions. Didn't get to most of the bug reports; I wanted
to
> > get D to be 'feature complete' first, the next version will be bug polishing. I'm setting sights on releasing D 1.0 by March.
> >
> > Lots of improvements to templates:
> >
> > o    No more instance keyword (though still supported for the time
being).
> > To instantiate template Foo with arguments a,b use:
> >     Foo!(a,b)
> > which is equivalent to the C++:
> >     Foo<a,b>
> > but doesn't have parsing problems.
> >
> > o If there's only one declaration in a template, and its name matches
the
> > template name, it is 'promoted' to the enclosing scope:
> >
> >     template Foo(T) { class Foo { T a,b; }}
> >     ...
> >     void func()
> >     {
> >         Foo(int) x;
> >         x.a = 3;
> >     }
> >
> > o As a shortcut to the above, the template could have been written as:
> >
> >     class Foo(T) { T a,b; }
> >
> > There is no equivalent shortcut for function templates, the syntax would look too awful. But this works:
> >
> >     template Max(T) { T Max(T a, T b) { return ... ; } }
> >     ...
> >         x = Max!(int)(5,7);
> >
> > o Templates can now take 'alias' parameters where any non-local symbol
can
> > be substituted:
> >
> >     template Foo(alias S) { int* x = &S; }
> >
> > See the changelog for more cool stuff:
> >
> > http://www.digitalmars.com/d/changelog.html
> >
> >
> >
>
>


January 03, 2004
Err, ignore me.

C
"C" <dont@respond.com> wrote in message
news:bt7cig$1kmb$1@digitaldaemon.com...
> Are your writing several collection classes ?  If so can you post when
your
> done ?
>
> C
>
>
> "Sean L. Palmer" <palmer.sean@verizon.net> wrote in message news:bt7cbt$1k9n$1@digitaldaemon.com...
> > This module causes an internal error "Internal error: e2ir.c 133":
(I'm
> > also having trouble with it not thinking dim and tfloat are defined in
> some
> > other methods... still trying to track that down)
> >
> > module vector;
> >
> > import std.intrinsic;
> >
> > import std.math;
> >
> > public:
> >
> > template VecTemplate(tfloat, int dim)
> >
> > {
> >
> > struct Vector
> >
> > {
> >
> > tfloat d[dim];
> >
> > Vector opMul(tfloat b) { Vector r; for (int i=0; i<dim; ++i) r.d[i] =
d[i]
> *
> > b; return r; }
> >
> > Vector opDiv(tfloat b) { return *this * (1/b); }
> >
> > tfloat opMul(Vector b) { tfloat r=0; for (int i=0; i<dim; ++i) r +=
d[i];
> > return r; }
> >
> > }
> >
> > tfloat sqr(Vector v)
> >
> > {
> >
> > return v * v;
> >
> > }
> >
> > tfloat abs(Vector v)
> >
> > {
> >
> > return sqrt(sqr(v));
> >
> > }
> >
> > }
> >
> > alias VecTemplate!(float,2) V2;
> >
> > alias V2.Vector Vector2;
> >
> > unittest
> >
> > {
> >
> > float n;
> >
> > Vector2 a,b,c;
> >
> > n = V2.sqr(a);
> >
> > n = V2.abs(a);
> >
> > n = V2.abs(b-a);
> >
> > }
> >
> >
> >
> > I'm not sure what to do about template methods sqr, abs, etc, as their namespace must be explicitly indicated... what I have above (V2 alias)
is
> > the most elegant solution I thought of so far.
> >
> > I think foreach has the potential to really clean up the implementation
of
> > this Vector template, and if I give it an opApply it will help users out too.
> >
> > Sean
> >
> > "Walter" <walter@digitalmars.com> wrote in message news:bt5esp$1o8d$1@digitaldaemon.com...
> > > Lots of new additions. Didn't get to most of the bug reports; I wanted

> to
> > > get D to be 'feature complete' first, the next version will be bug polishing. I'm setting sights on releasing D 1.0 by March.
> > >
> > > Lots of improvements to templates:
> > >
> > > o    No more instance keyword (though still supported for the time
> being).
> > > To instantiate template Foo with arguments a,b use:
> > >     Foo!(a,b)
> > > which is equivalent to the C++:
> > >     Foo<a,b>
> > > but doesn't have parsing problems.
> > >
> > > o If there's only one declaration in a template, and its name matches
> the
> > > template name, it is 'promoted' to the enclosing scope:
> > >
> > >     template Foo(T) { class Foo { T a,b; }}
> > >     ...
> > >     void func()
> > >     {
> > >         Foo(int) x;
> > >         x.a = 3;
> > >     }
> > >
> > > o As a shortcut to the above, the template could have been written as:
> > >
> > >     class Foo(T) { T a,b; }
> > >
> > > There is no equivalent shortcut for function templates, the syntax
would
> > > look too awful. But this works:
> > >
> > >     template Max(T) { T Max(T a, T b) { return ... ; } }
> > >     ...
> > >         x = Max!(int)(5,7);
> > >
> > > o Templates can now take 'alias' parameters where any non-local symbol
> can
> > > be substituted:
> > >
> > >     template Foo(alias S) { int* x = &S; }
> > >
> > > See the changelog for more cool stuff:
> > >
> > > http://www.digitalmars.com/d/changelog.html
> > >
> > >
> > >
> >
> >
>
>


January 03, 2004
I'm running into a situation where function bodies inside templates are instantiated and checked even if that instantiation is never used.  This is causing problems, in that I can't provide, say, setters that take more parameters than the vector template was instantiated with.  Those errors should happen during instantiation, but the instantiation should happen at point of call, not point of template instantiation.  You probably also can't have methods that utilize properties or methods of template parameters that some may have and others may not (such as ++ on float) even if the method is never actually used.

C++ dealt with this by mandating implementations not expand and check template methods until they are used.

Sean

module vector;

import std.intrinsic;

import std.math;

public:

template VecTemplate(tfloat, int dim)

{

struct Vector

{

tfloat d[dim];


void set(tfloat r) { foreach(inout tfloat v; d) v = r; }

void set(tfloat a0,tfloat a1) { d[0] = a0; d[1] = a1; for(int i=2; i<dim;
++i) d[i] = 0; }

void set(tfloat a0,tfloat a1,tfloat a2) { d[0] = a0; d[1] = a1; d[2] = a2;
for(int i=3; i<dim; ++i) d[i] = 0; } // error... d[2] is outside allowed
range, but this function is never called!

void set(tfloat a0,tfloat a1,tfloat a2,tfloat a3) { d[0] = a0; d[1] = a1;
d[2] = a2; d[3] = a3; for(int i=4; i<dim; ++i) d[i] = 0; } // error... d[2]
is outside allowed range

void set(tfloat[dim] r) { for (int i=0; i<dim; ++i) d[i] = r[i]; }

}
}
alias VecTemplate!(float,2) V2;

alias V2.Vector Vector2;

unittest

{

Vector2 b;

b.set(0);

b.set(0,1);

}

"Walter" <walter@digitalmars.com> wrote in message news:bt5esp$1o8d$1@digitaldaemon.com...
> Lots of new additions. Didn't get to most of the bug reports; I wanted to get D to be 'feature complete' first, the next version will be bug polishing. I'm setting sights on releasing D 1.0 by March.
>
> Lots of improvements to templates:


January 03, 2004
how about, instead of the promoting, following more the C++ syntax directly?

template(T) T max(T a,T b) { return a > b ? a : b; }

as equivalent to the current

template max(T) { T max(T a,T b) { return a > b ? a : b; } }

i don't see any syntactical problems with this.. and for the classes, that would work, too

template(T) class Container {
private T[] data;
}

instead of

template Container(T) { class Container {
private T[] data;
} }

or

class Container(T) {
private T[] data;
}

yes, the last is shorter, but i like to have a template keyword in each template declaration... btw, how do you create such a Container?

Container!(int) x = new Container!(int)(ctor-params here?);

because .77 just plain crashes all the time..

In article <bt5esp$1o8d$1@digitaldaemon.com>, Walter says...
>
>Lots of new additions. Didn't get to most of the bug reports; I wanted to get D to be 'feature complete' first, the next version will be bug polishing. I'm setting sights on releasing D 1.0 by March.
>
>Lots of improvements to templates:
>
>o    No more instance keyword (though still supported for the time being). To instantiate template Foo with arguments a,b use:
>    Foo!(a,b)
>which is equivalent to the C++:
>    Foo<a,b>
>but doesn't have parsing problems.
>
>o If there's only one declaration in a template, and its name matches the template name, it is 'promoted' to the enclosing scope:
>
>    template Foo(T) { class Foo { T a,b; }}
>    ...
>    void func()
>    {
>        Foo(int) x;
>        x.a = 3;
>    }
>
>o As a shortcut to the above, the template could have been written as:
>
>    class Foo(T) { T a,b; }
>
>There is no equivalent shortcut for function templates, the syntax would look too awful. But this works:
>
>    template Max(T) { T Max(T a, T b) { return ... ; } }
>    ...
>        x = Max!(int)(5,7);
>
>o Templates can now take 'alias' parameters where any non-local symbol can be substituted:
>
>    template Foo(alias S) { int* x = &S; }
>
>See the changelog for more cool stuff:
>
>http://www.digitalmars.com/d/changelog.html
>
>
>


January 03, 2004
"Jeroen van Bemmel" <someone@somewhere.com> wrote in message news:bt6dhd$6sm$1@digitaldaemon.com...
> About pragma's: couldn't these be implemented using versioning
functionality
> instead?
>
> Each compiler defines an identifier as its version already, and
proprietary
> extensions would then have to be enclosed in such version sections. For example:
>
> version (DigitalMars) {
>     __some_proprietary_keyword__ int x;
> } else {
>     int x;
> }

I'm pretty familiar with the proprietary keywords that are rampant in C and C++, and how new proprietary syntaxes constantly appear and evolve. The trouble with proprietary syntaxes is that different D compilers will not be able to parse them even if they are protected with a version statement. With the pragma syntax, proprietary extensions can be added in a way that other compilers can parse even if they cannot handle it otherwise.

> Reasoning behind this: I tend to prefer minimalistic feature sets

I agree with you!


January 03, 2004
"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:bt6jc4$flc$1@digitaldaemon.com...
> Walter wrote:
>
> >o    No more instance keyword (though still supported for the time
being).
> >To instantiate template Foo with arguments a,b use:
> >
> >
> Does this imply that your going to remove the instance keyword some time in the future?

Yes.

> If so, it might be a good idea, to remove it from the example documentation (such as on http://www.digitalmars.com/d/declaration.html#alias), to prevent new users from using it.

There's a spot I missed!

> PS - Sorry if I'm stating the obvious.

Stating the obvious is always a good idea, because often one misses the obvious.


January 03, 2004
"Sean L. Palmer" <palmer.sean@verizon.net> wrote in message news:bt79le$1gb0$1@digitaldaemon.com...
> Walter, do you see the template "limitations" being lifted in the future?

At the moment, we'll see how far we get with things as they are.


January 03, 2004
I'm mostly just working on mathematical vectors/matrices; personally I'm happy with builtin arrays and associative arrays for 99% of what I do.  I'm sure others on this NG are or will be working on collection templates.

Sean

"C" <dont@respond.com> wrote in message news:bt7cig$1kmb$1@digitaldaemon.com...
> Are your writing several collection classes ?  If so can you post when
your
> done ?
>
> C