www.digitalmars.com         C & C++   DMDScript  

D - dmd 0.51 release

reply "Walter" <walter digitalmars.com> writes:
www.digitalmars.com/d/changelog.html
Jan 27 2003
next sibling parent reply Burton Radons <loth users.sourceforge.net> writes:
class foo
{
     union
     {
         int i;
         char j;
     }
}

"class foo 2duplicate union initialization for j"
Jan 27 2003
parent reply "Sean L. Palmer" <seanpalmer directvinternet.com> writes:
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;
}
Jan 28 2003
parent reply "Walter" <walter digitalmars.com> writes:
"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

 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

 not a static, so it can't have a static initializer.".  Yet I can

 floats and ints that way just fine.  Just arrays are a problem.  I don't

 the need for the special case exclusion.  Eliminating initializers

 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

 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

 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.
Jan 28 2003
parent reply "Sean L. Palmer" <seanpalmer directvinternet.com> writes:
"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


 (by default)... seems counterintuitive.  Perhaps allow a boolean

 there?  Either that or add version(always) so we can just change always


 none and back instead of having to pull one of the version bodies out of

 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
Jan 28 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Sean L. Palmer" <seanpalmer directvinternet.com> wrote in message
news:b18081$p1k$1 digitaldaemon.com...
 You could try version(broken) <g>

version(none).

version(0)
 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 +=

 ?

Right!
Jan 29 2003
parent "Sean L. Palmer" <seanpalmer directvinternet.com> writes:
That's spookily similar to version(none) and I think it would be confusing.

Sean

"Walter" <walter digitalmars.com> wrote in message
news:b19773$1p9h$1 digitaldaemon.com...
 "Sean L. Palmer" <seanpalmer directvinternet.com> wrote in message
 news:b18081$p1k$1 digitaldaemon.com...
 You could try version(broken) <g>

version(none).

version(0)

Jan 30 2003
prev sibling next sibling parent reply "Ben Woodhead" <zander echotech.ca> writes:
Hello Everybody

Is there a testing harness to go with D.

Ben
Jan 28 2003
parent reply "Walter" <walter digitalmars.com> writes:
"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?
Jan 28 2003
parent reply "Ben Woodhead" <zander echotech.ca> writes:
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?

Jan 28 2003
parent reply "Walter" <walter digitalmars.com> writes:
"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

 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

 have a harness testing all the possible ways you could use templates then

 the docs for templates you can point them to the testing harness code.

Check out the unit test feature of D.
Jan 28 2003
parent reply "Ken Carpenter" <kencr shaw.ca> writes:
"Walter" <walter digitalmars.com> wrote in message
news:b16ogp$v5m$1 digitaldaemon.com...
 "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

 the code generation against. A possible example would be a program that
 tests dynamic arrays, it would be good to check regressions as well.

Check out the unit test feature of D.

I think he meant something more like a validation suite (which could be implemented as unit tests). That would let all the budding D-compiler writers out there ensure that they had implemented all the language features correctly. Ken Carpenter
Jan 29 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Ken Carpenter" <kencr shaw.ca> wrote in message
news:b184gl$ssa$1 digitaldaemon.com...
 I think he meant something more like a validation suite (which could be
 implemented as unit tests).  That would let all the budding D-compiler
 writers out there ensure that they had implemented all the language
 features correctly.

I do have the beginnings of one. It isn't thorough, though.
Jan 29 2003
parent "Ben Woodhead" <zander echotech.ca> writes:
Hello

Ya, ken is right. I was looking for something as a validation suite.

Thanks for your responces.
Ben

"Walter" <walter digitalmars.com> wrote in message
news:b19774$1p9h$2 digitaldaemon.com...
 "Ken Carpenter" <kencr shaw.ca> wrote in message
 news:b184gl$ssa$1 digitaldaemon.com...
 I think he meant something more like a validation suite (which could be
 implemented as unit tests).  That would let all the budding D-compiler
 writers out there ensure that they had implemented all the language
 features correctly.

I do have the beginnings of one. It isn't thorough, though.

Jan 30 2003
prev sibling parent Burton Radons <loth users.sourceforge.net> writes:
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.
Jan 28 2003