questions on class definitions and mixins

Adam D. Ruppe destructionator at gmail.com
Mon Feb 10 07:41:03 PST 2014


On Monday, 10 February 2014 at 15:35:00 UTC, Patrick D. Jeeves 
wrote:
> From what I can gather constructs like this just aren't allowed 
> in D, but I don't understand why, can anyone explain it please?

It just wasn't there but there's some people who think it would 
be a good idea to add (including Walter I think) so it might be 
in later.


What you can do is write it all inline, then do a create an 
automatic documentation or interface file with dmd -D or dmd -H 
which strips out most the function bodies.

> The other thing I want to know is about the mixin() command, 
> and what the limitations of it are; I know it runs an 
> interpreted version of D

mixin basically copy/pastes the code inside right into the source 
file then compiles it normally. The interpreted part is only 
running the function to create teh code, but then the created 
code is compiled normally.

So

mixin(foo());

foo() is interpreted, then the return value of it is compiled in 
normally.

> Is this because it isn't possible to do such things, or because 
> it would be rather pointless to do so compared to simpler 
> approaches, (in this case calling the C function output by 
> flex/bison).

I think it is just that nobody has tried yet. There are parser 
generators that work at compile time in D though 
https://github.com/PhilippeSigaud/Pegged for example


More information about the Digitalmars-d-learn mailing list