On Thu, Jun 26, 2014 at 10:38:53AM +0000, bearophile via Digitalmars-d wrote: [...] > -------------------- > > This proposes a __traits(documentation, expr): > https://github.com/D-Programming-Language/dmd/pull/3531 > > Something similar is used in Python and Lisp, it allows to introspect > the comments. It's useful for various generative purposes. > > One quirk of this implementation, that I am not sure about: > > >Comments will only be available if DMD is invoked with the "-D" flag. > >If no comment is available for expr, __traits(comment, expr) > >evaluates to the empty string.<
This is probably because without -D, the entire ddoc code doesn't even run (which probably saves on compilation time), and comments are not kept by the parser/lexer, so by the time the compiler evaluates __traits(comment...), it doesn't know how to retrieve the comments anymore. [...] > -------------------- > > https://github.com/D-Programming-Language/dmd/pull/3615 > > Will allow very handy, more DRY and less bug-prone like this: > > // static array type > int[$] a1 = [1,2]; // int[2] > auto[$] a2 = [3,4,5]; // int[3] > const[$] a3 = [6,7,8]; // const(int[3]) > > // dynamic array type > immutable[] a4 = [1,2]; // immutable(int)[] > shared[] a5 = [3,4,5]; // shared(int)[] > // partially specified part is unqualified. > > // pointer type > auto* p1 = new int(3); // int* > const* p2 = new int(3); // const(int)* > > // mixing > auto[][$] x1 = [[1,2,3],[4,5]]; // int[][2] > shared*[$] x2 = [new int(1), new int(2)]; // shared(int)*[2] I like this very much. I hope it will get merged in one form or another eventually. > A comment by Walter: > > >My reservation on this is I keep thinking there must be a better way > >than [$].< Is the only objection one about syntax? Surely professional bikeshedders like us can easily come up with more palatable syntaxes? ;-) > -------------------- > > https://github.com/D-Programming-Language/dmd/pull/3638 > > Allows to write code like: > > > void main() { > import std.algorithm; > alias sqr = a => a ^^ 2; > auto r = [1, 2, 3].map!sqr; > } > > > Currently you need to write: > > alias F(alias f) = f; > void main() { > import std.algorithm; > alias sqr = F!(a => a ^^ 2); > auto r = [1, 2, 3].map!sqr; > } [...] What's wrong with just writing auto? auto sqr = a => a^^2; auto r = [1,2,3].map!sqr; T -- The peace of mind---from knowing that viruses which exploit Microsoft system vulnerabilities cannot touch Linux---is priceless. -- Frustrated system administrator.
