www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is D actually |-----------this-----powerful-----------|?

reply "David Piepgrass" <qwertie256 gmail.com> writes:
I do believe D is my new favorite language. I'm trying to figure 
out just how far you can take D... here's my question from 
StackOverflow:

http://stackoverflow.com/questions/10962541/is-d-powerful-enough-for-these-features

"For the longest time I wanted to design a programming language 
that married extensibility with efficiency. I recently 
rediscovered D and I am wondering if D 2.0 is pretty much the 
language I wanted to make myself. What I love most is the 
potential of metaprogramming; in theory, could D's traits system 
enable the following features at compile time?"

"1. Run-time reflection: Are the compile-time reflection features 
sufficient to build a run-time reflection system a la Java/.NET?"

"2. Code conversion: Using a metaprogram, create C#/C++/etc. 
versions of your D program every time you compile it (bonus point 
if doc comments can be propagated)."

"3. Traits. I don't mean the metaprogramming traits built into D, 
I mean object-oriented traits for class composition. A D program 
would indicate a set of traits to compose, and a metaprogram 
would compose them."

"4. Unit inference engine: Given some notation for optionally 
indicating units, e.g. unit(value), could a D metaprogram examine 
the following code, infer the correct units, and issue an error 
message on the last line? (I wrote such a thing for boo so I can 
assure you this is possible in general, program-wide):"
Jun 09 2012
next sibling parent "David Piepgrass" <qwertie256 gmail.com> writes:
Oops, forgot the code.

 "4. Unit inference engine: Given some notation for optionally 
 indicating units, e.g. unit(value), could a D metaprogram 
 examine the following code, infer the correct units, and issue 
 an error message on the last line?

auto mass = kg(2.0); auto accel = 1.0; auto force = mass*accel; accel += metresPerSecondSquared(9.81); // units of 'force' and 'accel' now known force += pounds(3.0); // unit mismatch detected P.S. And can D output 'pre-processed' source, i.e. the code after metaprograms have executed?
Jun 09 2012
prev sibling next sibling parent Johannes Pfau <nospam example.com> writes:
Am Sat, 09 Jun 2012 19:07:17 +0200
schrieb "David Piepgrass" <qwertie256 gmail.com>:

 Oops, forgot the code.
 
 "4. Unit inference engine: Given some notation for optionally 
 indicating units, e.g. unit(value), could a D metaprogram 
 examine the following code, infer the correct units, and issue 
 an error message on the last line?

auto mass = kg(2.0); auto accel = 1.0; auto force = mass*accel; accel += metresPerSecondSquared(9.81); // units of 'force' and 'accel' now known force += pounds(3.0); // unit mismatch detected

There are some implementations (I think 2 or 3 have been announced on the newsgroup) which do exactly that. Take a look at this one, for example: https://github.com/klickverbot/phobos/blob/units/std/units.d http://klickverbot.at/code/units/std_units.html http://klickverbot.at/code/units/std_si.html There was some talk about including something like that in the standard library, but that discussion went nowhere.
 P.S. And can D output 'pre-processed' source, i.e. the code after 
 metaprograms have executed?

There's a patch for dmd which does that, but it hasn't been merged yet. https://github.com/D-Programming-Language/dmd/pull/426
Jun 10 2012
prev sibling parent "Kagamin" <spam here.lot> writes:
On Saturday, 9 June 2012 at 17:07:19 UTC, David Piepgrass wrote:
 auto mass = kg(2.0);
 auto accel = 1.0;
 auto force = mass*accel;
 accel += metresPerSecondSquared(9.81); // units of 'force' and 
 'accel' now known
 force += pounds(3.0);                  // unit mismatch detected

accel will be double. I guess you want bidirectional type inference. I think it was done for python, but resulted in too big compilation times (the times are ok for a helloworld).
Jun 13 2012