Jump to page: 1 2
Thread overview
dmd 0.51 release
Jan 27, 2003
Walter
Jan 28, 2003
Burton Radons
Jan 28, 2003
Sean L. Palmer
Jan 28, 2003
Walter
Jan 29, 2003
Sean L. Palmer
Jan 29, 2003
Walter
Jan 30, 2003
Sean L. Palmer
Jan 28, 2003
Ben Woodhead
Jan 28, 2003
Walter
Jan 28, 2003
Ben Woodhead
Jan 28, 2003
Walter
Jan 29, 2003
Ken Carpenter
Jan 29, 2003
Walter
Jan 30, 2003
Ben Woodhead
Jan 28, 2003
Burton Radons
January 27, 2003
www.digitalmars.com/d/changelog.html




January 28, 2003
class foo
{
    union
    {
        int i;
        char j;
    }
}

"class foo 2duplicate union initialization for j"

January 28, 2003
Here's something interesting:

Trying to use the new template stuff, and operator overloading, to do something useful.  Seems it's a real hassle to always have to prepend the template instance identifier.  Seems you should be able to import the template instance or use a with statement.  If you try to use a template instance in a with clause however it crashes DMD.  ;)

Also, can you please go ahead and implement array operations?  It's been a long time since they were introduced and still no implementation.  I'm thinking maybe you forgot, but probably have been too busy.  It'll be a cool feature once it's in.  Also still can't construct literal arrays except at global scope.  If you do one at local scope it complains:  "Variable blah is not a static, so it can't have a static initializer.".  Yet I can initialize floats and ints that way just fine.  Just arrays are a problem.  I don't see the need for the special case exclusion.  Eliminating initializers entirely seems like going back to the stone age;  having them only work for simple types seems just wrong.

One other small thing I noticed is that you can't do version(0) {
breaks(); } version(1) { runs(); } because version 0 is what gets compiled
(by default)... seems counterintuitive.  Perhaps allow a boolean expression
there?  Either that or add version(always) so we can just change always to
none and back instead of having to pull one of the version bodies out of the
version and put the other one inside a version, to switch back and forth
between two mutually exclusive code sections.

Also I'm not sure what the return type should be for addass;  does the compiler even want a return type for those?

After getting used to C++, the lack of ctors for structs and the explicit nature of templates seems really limiting.

Good work on the value template params, Walter.  I bet Daniel will get a real kick out of those!  ;)

Sean

// Test to manipulate 3D vectors, in D!
// by Sean L Palmer (seanpalmer@directvinternet.com)
// This code is released without any warranty.  Use at your own risk.
import stream;
import string;
import c.stdio;
import math;

template VecTemplate(tfloat, int dim:3)
{
 struct Vector
 {
  tfloat d[dim];

  version(none)
  {
   // sets the vector to the value of the given array
   void set(tfloat[dim] r) { d[] = r[]; }
   // comparison (a == b, a != b)
   bool eq(Vector b) { for (int i=0; i<dim; ++i) if (d[i] != b.d[i]) return
false; return true; }
   // negate (-a)
   Vector neg() { Vector r; for (int i=0; i<dim; ++i) r.d[i] = -d[i]; return
r;  }
   // complement (~a)
   Vector com() { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[(i+1)%dim];
d[0] = -d[0]; return r;  }
   // add (a + b)
   Vector add(Vector b) { Vector r; r.d[] = d[] + b.d[]; return r;  }
   // addto (a += b)
   Vector addass(Vector b) { d[] += b.d[]; return r;  }
   // subtract (a - b)
   Vector sub(Vector b) { Vector r; r.d[] = d[] - b.d[]; return r;  }
   // multiply by scalar (a * 2.0)
   Vector mul(tfloat b) { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[i]
* b; return r;  }
   // divide by scalar (a / b)
   Vector div(tfloat b) { return *this * (1/b);  }
   // dot product (a * b)
   tfloat mul(Vector b) { tfloat r=0; for (int i=0; i<dim; ++i) r += d[i];
return r;  }
   // outer product (a ^ b)
   //Vector xor(Vector b) { Vector r; for (int i=0; i<dim; ++i) r += d[i];
return r;  }
  }

  void set(tfloat[dim] r) { for (int i=0; i<dim; ++i) d[i] = r[i]; }
  // comparison (a == b, a != b)
  bit eq(Vector b) { for (int i=0; i<dim; ++i) if (d[i] != b.d[i]) return
false; return true; }
  // negate (-a)
  Vector neg() { Vector r; for (int i=0; i<dim; ++i) r.d[i] = -d[i]; return
r;  }
  // complement (~a)
  Vector com() { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[(i+1)%dim];
d[0] = -d[0]; return r;  }
  // add (a + b)
  Vector add(Vector b) { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[i] +
b.d[i]; return r;  }
  // addto (a += b)
  Vector addass(Vector b) { for (int i=0; i<dim; ++i) d[i] += b.d[i]; return
*this; }
  // subtract (a - b)
  Vector sub(Vector b) { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[i] -
b.d[i]; return r;  }
  // multiply by scalar (a * 2.0)
  Vector mul(tfloat b) { Vector r; for (int i=0; i<dim; ++i) r.d[i] = d[i] *
b; return r;  }
  // divide by scalar (a / b)
  Vector div(tfloat b) { return *this * (1/b);  }
  // dot product (a * b)
  tfloat mul(Vector b) { tfloat r=0; for (int i=0; i<dim; ++i) r += d[i];
return r;  }
  // outer product (a ^ b)
  //Vector xor(Vector b) { Vector r; for (int i=0; i<dim; ++i) r += d[i];
return r;  }

  void print() { for (int i=0; i<dim; ++i) printf("%f ", d[i]);
printf("\n"); }
 }

 tfloat abs(Vector v)
 {
  return sqrt(sqr(v));
 }

 tfloat sqr(Vector v)
 {
  return v * v;
 }
}

instance VecTemplate(float, 3) VcT;

float[3] up = [ 0, 1, 0 ];

int main(char[][] args)
{
 printf("running\n");
 //with (VcT)         // try this, I dare ya!!  crashes DMD 0.51
 {
  VcT.Vector a,b,c;
  c.set(up);
  b.set(up);
  a = b + c;
  a.print();
  printf("b * c = %f\n",b * c);
  printf("abs(a) = %f\n",VcT.abs(a));
  printf("sqr(a) = %f\n",VcT.sqr(a));
 }
 Sleep(1000);
 printf("closing\n");
 return 0;
}



January 28, 2003
Hello Everybody

Is there a testing harness to go with D.

Ben


January 28, 2003
"Ben Woodhead" <zander@echotech.ca> wrote in message news:b166qo$jis$1@digitaldaemon.com...
> Is there a testing harness to go with D.

What do you mean?


January 28, 2003
Hello Walter.

Basically what I mean is something to compile. Something that you can check the code generation against. A possible example would be a program that tests dynamic arrays, it would be good to check regressions as well.

Having a testing harness would also be helpful for documentation. Ie, if you have a harness testing all the possible ways you could use templates then in the docs for templates you can point them to the testing harness code.

Ben

"Walter" <walter@digitalmars.com> wrote in message news:b16aud$mie$1@digitaldaemon.com...
>
> "Ben Woodhead" <zander@echotech.ca> wrote in message news:b166qo$jis$1@digitaldaemon.com...
> > Is there a testing harness to go with D.
>
> What do you mean?
>
>


January 28, 2003
int [uint []] foo;
void main () { null in foo; }

"Symbol Undefined __init_TypeInfo_Ak"

I know what the problem is; just thought I'd note that there uses for real TypeInfo objects.

January 28, 2003
"Ben Woodhead" <zander@echotech.ca> wrote in message news:b16c2o$n78$1@digitaldaemon.com...
> Basically what I mean is something to compile. Something that you can
check
> the code generation against. A possible example would be a program that tests dynamic arrays, it would be good to check regressions as well.
>
> Having a testing harness would also be helpful for documentation. Ie, if
you
> have a harness testing all the possible ways you could use templates then
in
> the docs for templates you can point them to the testing harness code.

Check out the unit test feature of D.


January 28, 2003
"Sean L. Palmer" <seanpalmer@directvinternet.com> wrote in message news:b15lq9$aj0$1@digitaldaemon.com...
> Trying to use the new template stuff, and operator overloading, to do something useful.  Seems it's a real hassle to always have to prepend the template instance identifier.  Seems you should be able to import the template instance or use a with statement.  If you try to use a template instance in a with clause however it crashes DMD.  ;)

I'll check it out.

> Also, can you please go ahead and implement array operations?  It's been a long time since they were introduced and still no implementation.  I'm thinking maybe you forgot, but probably have been too busy.  It'll be a
cool
> feature once it's in.  Also still can't construct literal arrays except at global scope.  If you do one at local scope it complains:  "Variable blah
is
> not a static, so it can't have a static initializer.".  Yet I can
initialize
> floats and ints that way just fine.  Just arrays are a problem.  I don't
see
> the need for the special case exclusion.  Eliminating initializers
entirely
> seems like going back to the stone age;  having them only work for simple types seems just wrong.

It's always hard to figure out what is the most important thing to work on next, I did the template things because Daniel needs it to work on his D template library.

> One other small thing I noticed is that you can't do version(0) {
> breaks(); } version(1) { runs(); } because version 0 is what gets compiled
> (by default)... seems counterintuitive.  Perhaps allow a boolean
expression
> there?  Either that or add version(always) so we can just change always to none and back instead of having to pull one of the version bodies out of
the
> version and put the other one inside a version, to switch back and forth between two mutually exclusive code sections.

You could try version(broken) <g>

> Also I'm not sure what the return type should be for addass;  does the compiler even want a return type for those?

That'd be up to the programmer.


January 29, 2003
"Walter" <walter@digitalmars.com> wrote in message news:b16r4m$111b$1@digitaldaemon.com...
> It's always hard to figure out what is the most important thing to work on next, I did the template things because Daniel needs it to work on his D template library.

Not a problem.  Just hoping it's in the queue.  ;)

> > One other small thing I noticed is that you can't do version(0) {
> > breaks(); } version(1) { runs(); } because version 0 is what gets
compiled
> > (by default)... seems counterintuitive.  Perhaps allow a boolean
> expression
> > there?  Either that or add version(always) so we can just change always
to
> > none and back instead of having to pull one of the version bodies out of
> the
> > version and put the other one inside a version, to switch back and forth between two mutually exclusive code sections.
>
> You could try version(broken) <g>

I meant a predefined version that is always enabled.  The opposite of
version(none).

> > Also I'm not sure what the return type should be for addass;  does the compiler even want a return type for those?
>
> That'd be up to the programmer.

So if you write void addass(int rhs) then you can no longer do a += (b += c)
?

That's very flexible.  Sweet!

Sean


« First   ‹ Prev
1 2