digitalmars.D - New Traits
- John Maschmeyer (16/16) May 14 2012 I implemented some new traits that seemed to have a lot of
- Jacob Carlborg (4/20) May 14 2012 Wow, all these are awesome. Nice work.
- Philippe Sigaud (5/13) May 15 2012 Awesome!
- John Maschmeyer (40/43) May 15 2012 import std.stdio;
- Philippe Sigaud (20/31) May 16 2012 (examples)
- John Maschmeyer (5/14) May 16 2012 int foo();
- Jacob Carlborg (4/8) May 17 2012 Awesome, now where is that CTFE D compiler :)
- F i L (4/20) May 15 2012 This is great! Can't wait to use these in action (codeof mostly),
- Nick Sabalausky (3/5) May 15 2012 Little too late for that. Maybe for 2.060, though.
- Justin Whear (3/23) May 16 2012 Does codeof work with lambda literals? If so, I'm envisioning a LINQ-to-
- Jacob Carlborg (6/8) May 16 2012 That would be awesome to do. Actually, if D had operator overloading
- John Maschmeyer (12/15) May 16 2012 It works for a function literal that has been assigned to a
- Jacob Carlborg (9/19) May 17 2012 Does it work if the lambda is passed to a function:
- John Maschmeyer (7/13) May 17 2012 Unforutnately, no. As written the lambda is a runtime parameter,
- Justin Whear (5/21) May 17 2012 An alias parameter to a template would actually be the ideal use-case fo...
- John Maschmeyer (18/25) May 17 2012 I just pushed an update that should support this.
- Jacob Carlborg (4/12) May 17 2012 Very nice.
I implemented some new traits that seemed to have a lot of interest recently. I've implemented parameterNames, isPublic, isPrivate, isProtected, isPackge, isExport, and codeof traits. parameterNames lets you get access to the names of function parameters isPublic, isPrivate, etc let you query access modifiers codeof was discussed recently in http://forum.dlang.org/thread/huyqfcoosgzfneswnrur forum.dlang.org. It gives you access to the source code of functions, classes, etc. I'm pretty new to the dmd code, so could someone take a look at them? https://github.com/D-Programming-Language/dmd/pull/951 https://github.com/D-Programming-Language/dmd/pull/952 https://github.com/D-Programming-Language/dmd/pull/953
May 14 2012
On 2012-05-15 01:13, John Maschmeyer wrote:I implemented some new traits that seemed to have a lot of interest recently. I've implemented parameterNames, isPublic, isPrivate, isProtected, isPackge, isExport, and codeof traits. parameterNames lets you get access to the names of function parameters isPublic, isPrivate, etc let you query access modifiers codeof was discussed recently in http://forum.dlang.org/thread/huyqfcoosgzfneswnrur forum.dlang.org. It gives you access to the source code of functions, classes, etc. I'm pretty new to the dmd code, so could someone take a look at them? https://github.com/D-Programming-Language/dmd/pull/951 https://github.com/D-Programming-Language/dmd/pull/952 https://github.com/D-Programming-Language/dmd/pull/953Wow, all these are awesome. Nice work. -- /Jacob Carlborg
May 14 2012
On Tue, May 15, 2012 at 1:13 AM, John Maschmeyer <jmaschme gmail.com> wrote= :I implemented some new traits that seemed to have a lot of interest recently.I've implemented parameterNames, isPublic, isPrivate, isProtected, isPackge, isExport, and codeof traits.codeof was discussed recently in http://forum.dlang.org/thread/huyqfcoosgzfneswnrur forum.dlang.org. =C2=A0 It gives you access to the source code of functions, classes, etc.Awesome! Can you give us a simple example of what codeof produces? How does it deal with functions overloads?
May 15 2012
On Tuesday, 15 May 2012 at 17:18:57 UTC, Philippe Sigaud wrote:Can you give us a simple example of what codeof produces? How does it deal with functions overloads?import std.stdio; void bar() { writeln("testing"); } struct Foo { public: int x; int y; } void main() { writeln("*************"); writeln(__traits(codeof, bar)); writeln("*************"); writeln(__traits(codeof, Foo)); writeln("*************"); } This prints: ************* void bar() { writeln("testing"); } ************* struct Foo { public { int x; int y; } } ************* I'm not sure how well this works with overloads. If you just use the symbol name, it works like other traits and returns the source code for the first match. I tried using the getOverloads trait and some alias magic, but all I've been able to do so far is get the prototype for overloads. I'm guessing it has something to do with using an alias instead of the actual symbol. I think we need a better way to reference an overloaded symbol.
May 15 2012
On Tue, May 15, 2012 at 11:09 PM, John Maschmeyer <jmaschme gmail.com> wrot= e:On Tuesday, 15 May 2012 at 17:18:57 UTC, Philippe Sigaud wrote:(examples)Can you give us a simple example of what codeof produces? How does it deal with functions overloads?*************Wonderful. I'm already salivating, er I mean I'm quite eager to get my hands on it. Jeebus, we will be able to do wonderful things with this. Code extraction, parsing, AST modif and then code re-creation and mixin. If you give it a module name (qualified with package name), does it output the entire module code?I'm not sure how well this works with overloads. =C2=A0If you just use th=e symbolname, it works like other traits and returns the source code for the firs=tmatch. =C2=A0I tried using the getOverloads trait and some alias magic, b=ut allI've been able to do so far is get the prototype for overloads. =C2=A0I'm guessing it has something to do with using an alias instead of the actual symbol. =C2=A0I think we need a better way to reference an overloaded sym=bol. Don't sweat it for now. It's a bit more uncommon. what does this output? int foo() { return 0;} int foo(int i) { return i+1; } void foo(double d) { } foreach(i,overload; __traits(getOverloads, "foo")) writeln(overload.codef);
May 16 2012
On Wednesday, 16 May 2012 at 17:08:43 UTC, Philippe Sigaud wrote:If you give it a module name (qualified with package name), does it output the entire module code?Yeswhat does this output? int foo() { return 0;} int foo(int i) { return i+1; } void foo(double d) { } foreach(i,overload; __traits(getOverloads, "foo")) writeln(overload.codef);int foo(); int foo(int i); void foo(double d);
May 16 2012
On 2012-05-16 23:20, John Maschmeyer wrote:On Wednesday, 16 May 2012 at 17:08:43 UTC, Philippe Sigaud wrote:Awesome, now where is that CTFE D compiler :) -- /Jacob CarlborgIf you give it a module name (qualified with package name), does it output the entire module code?Yes
May 17 2012
On Monday, 14 May 2012 at 23:13:29 UTC, John Maschmeyer wrote:I implemented some new traits that seemed to have a lot of interest recently. I've implemented parameterNames, isPublic, isPrivate, isProtected, isPackge, isExport, and codeof traits. parameterNames lets you get access to the names of function parameters isPublic, isPrivate, etc let you query access modifiers codeof was discussed recently in http://forum.dlang.org/thread/huyqfcoosgzfneswnrur forum.dlang.org. It gives you access to the source code of functions, classes, etc. I'm pretty new to the dmd code, so could someone take a look at them? https://github.com/D-Programming-Language/dmd/pull/951 https://github.com/D-Programming-Language/dmd/pull/952 https://github.com/D-Programming-Language/dmd/pull/953This is great! Can't wait to use these in action (codeof mostly), hopefully it'll make it into 2.030. :D
May 15 2012
"F i L" <witte2008 gmail.com> wrote in message news:amhbhvoaaxncbyalouuv forum.dlang.org...This is great! Can't wait to use these in action (codeof mostly), hopefully it'll make it into 2.030.Little too late for that. Maybe for 2.060, though. </smartass>
May 15 2012
On Tue, 15 May 2012 01:13:27 +0200, John Maschmeyer wrote:I implemented some new traits that seemed to have a lot of interest recently. I've implemented parameterNames, isPublic, isPrivate, isProtected, isPackge, isExport, and codeof traits. parameterNames lets you get access to the names of function parameters isPublic, isPrivate, etc let you query access modifiers codeof was discussed recently in http://forum.dlang.org/thread/huyqfcoosgzfneswnrur forum.dlang.org. It gives you access to the source code of functions, classes, etc. I'm pretty new to the dmd code, so could someone take a look at them? https://github.com/D-Programming-Language/dmd/pull/951 https://github.com/D-Programming-Language/dmd/pull/952 https://github.com/D-Programming-Language/dmd/pull/953Does codeof work with lambda literals? If so, I'm envisioning a LINQ-to- SQL-esque library.
May 16 2012
On 2012-05-16 19:04, Justin Whear wrote:Does codeof work with lambda literals? If so, I'm envisioning a LINQ-to- SQL-esque library.That would be awesome to do. Actually, if D had operator overloading that worked a bit more like it does in C++ that would be sufficient in most cases. -- /Jacob Carlborg
May 16 2012
On Wednesday, 16 May 2012 at 17:04:32 UTC, Justin Whear wrote:Does codeof work with lambda literals? If so, I'm envisioning a LINQ-to- SQL-esque library.It works for a function literal that has been assigned to a variable. Function Literal: int function(int) func = x => x+1; writeln(__traits(codeof, func)); Outputs: int function(int) func = delegate pure nothrow safe int(int x) { return x + 1; } ;
May 16 2012
On 2012-05-16 23:19, John Maschmeyer wrote:It works for a function literal that has been assigned to a variable. Function Literal: int function(int) func = x => x+1; writeln(__traits(codeof, func)); Outputs: int function(int) func = delegate pure nothrow safe int(int x) { return x + 1; } ;Does it work if the lambda is passed to a function: void foo (int delegate (int x) dg) { wirteln(__traits(codeof, dg); } foo(x => x + 1); -- /Jacob Carlborg
May 17 2012
On Thursday, 17 May 2012 at 10:30:26 UTC, Jacob Carlborg wrote:Does it work if the lambda is passed to a function: void foo (int delegate (int x) dg) { wirteln(__traits(codeof, dg); } foo(x => x + 1);Unforutnately, no. As written the lambda is a runtime parameter, so there is no way the trait can get the actual function code. Instead, all that will print is the signature of the delegate. If that were a template parameter, it would theoretically be possible to print the lambda expression, but as currently implemented it doesn't.
May 17 2012
On Thu, 17 May 2012 23:20:01 +0200, John Maschmeyer wrote:On Thursday, 17 May 2012 at 10:30:26 UTC, Jacob Carlborg wrote:An alias parameter to a template would actually be the ideal use-case for what I have in mind. Essentially, it would work just like map/reduce/ filter (function passed by alias), but translate the lambda to SQL/XPath/ etc.Does it work if the lambda is passed to a function: void foo (int delegate (int x) dg) { wirteln(__traits(codeof, dg); } foo(x => x + 1);Unforutnately, no. As written the lambda is a runtime parameter, so there is no way the trait can get the actual function code. Instead, all that will print is the signature of the delegate. If that were a template parameter, it would theoretically be possible to print the lambda expression, but as currently implemented it doesn't.
May 17 2012
On Thursday, 17 May 2012 at 21:39:03 UTC, Justin Whear wrote:An alias parameter to a template would actually be the ideal use-case for what I have in mind. Essentially, it would work just like map/reduce/ filter (function passed by alias), but translate the lambda to SQL/XPath/ etc.I just pushed an update that should support this. It can now resolve aliases and lambdas properly. This means things like this will work correctly. module pack.test; int foo() { return 0;} int foo(int i) { return i+1; } void foo(double d) { } foreach(overload; __traits(getOverloads, pack.test, "foo")) writeln(__traits(codeof, overload); Also, passing lambdas via template alias parameters works. So something like this should work as well. void foo(alias dg)() { writeln(__traits(codeof, dg)); } void main() { foo!(x=>x+1)(); }
May 17 2012
On 2012-05-18 04:21, John Maschmeyer wrote:Also, passing lambdas via template alias parameters works. So something like this should work as well. void foo(alias dg)() { writeln(__traits(codeof, dg)); } void main() { foo!(x=>x+1)(); }Very nice. -- /Jacob Carlborg
May 17 2012