On Tue, Sep 14, 2010 at 17:01, Andrei Alexandrescu < seewebsiteforem...@erdani.org> wrote: > > I think we'll move forward with that one. I'll start working on the content. Ideas for good tutorial examples? >
Maybe more examples of what's interesting me right now than tutorials, but who knows? * executing command-lines instructions from a D program. Theme: file I/O, OS interaction. An interesting example is having a script that loads a D file, modifies its source, asks for DMD to compile it and then runs it and get its result. It could be the first brick to get a REPL / idmd (interactive dmd). Maybe more a [challenge] subject than a tutorial example? * fun with types and operator overload: auto g = gobble ~1 ~ "a" ~ 2.34 ~ (int i) { return i*i;} ~ [1,2,3]; struct Gobbler(T...) is just a tuple-like type overloading opBinary!("~", U)(U u) to return Gobbler!(T, U)(this.payload, u). gobble() is just a helper function returning Gobbler!() The type is evolving along with the expression consumption. I find this fascinating. Statically typed variadic expressions: how many language offer this? How many lines of C++? Now, if only alias this worked for typetuples, we could even do g[3] to get the function literal back. * related to this: expressions templates in D. cpp-next has a nice article introducing Boost.Proto and such. http://cpp-next.com/archive/2010/08/expressive-c-introduction/ I'm reading the Boost.Proto docs right now and find them quite interesting. Variable!double _1, _2; auto expr = (_1 + _2)*_1 + 1; // expr encodes the entire expression in its type and is a callable struct. In D, it could be a BinOp!("+", BinOp!("*", BinOp!("+", Variable!double,Variable!double),Variable!double),int) * a small script that find ddocs comments from D code and find any fri****g missing parenthesis, telling the user were in the file she should look (and range of line spanning the comment). Finding ddocs comments and counting open/closed parenthesis is a simple example of parsing/finite state automata. * some interesting examples of templates or string mixins could help alleviate the sentiment they are unknowable black magic. I admit it, I have no interesting/new example in mind right now. Some example where a custom struct is created according to CT parameters could be interesting. Philippe