Re: Need runtime reflection?

2012-07-18 Thread lijie
On Wed, Jul 18, 2012 at 2:59 PM, Jacob Carlborg wrote: > I think you can pass a module to a template via an alias parameter. Then > the template should be able to inspect all free functions using something > like __traits(allMembers). > > Have a problem. -- // file: A.d module A; // functions

Re: Need runtime reflection?

2012-07-18 Thread lijie
On Wed, Jul 18, 2012 at 2:59 PM, Jacob Carlborg wrote: > On 2012-07-18 06:10, lijie wrote: > > Free functions support is hard, with runtime cast, I just think compile >> time. >> > > It's possibly to implement runtime reflection by loading the running > e

Re: Need runtime reflection?

2012-07-17 Thread lijie
On Tue, Jul 17, 2012 at 11:08 PM, David Piepgrass wrote: > > I, too, was enamored with Go Interfaces and implemented them for .NET: > > http://www.codeproject.com/**Articles/87991/Dynamic-** > interfaces-in-any-NET-language

Need runtime reflection?

2012-07-16 Thread lijie
I want to imitate golang's interface in D, to study D's template. I wrote some code: https://gist.github.com/3123593 Now we can write code like golang: -- interface IFoo { void foo(int a, string b, float c); } struct Foo { void foo(int a, string b, float c) { writeln("Foo.foo: ",

Re: A delegate problem, create delegation in loop

2012-07-06 Thread lijie
On Fri, Jul 6, 2012 at 3:06 PM, Timon Gehr wrote: > > It is simple. Variable declarations introduce a new variable. Closures > that reference the same variable will see the same values. > > > > foreach(i; 0..3) { functions~={writeln(i);}; } > > is the same as > > for(int i=0;i<3;i++) { funct

Re: A delegate problem, create delegation in loop

2012-07-05 Thread lijie
On Thu, Jul 5, 2012 at 4:26 PM, Denis Shelomovskij < verylonglogin@gmail.com> wrote: > Different situation is for such C# loop: > --- > for (int i = 0; i < funcs.Length; ++i) > { > int t = i; > funcs[i] = new MyFunc(() => System.Console.WriteLine(t)); > } > --- > where "t" is local fo

Re: A delegate problem, create delegation in loop

2012-07-05 Thread lijie
On Thu, Jul 5, 2012 at 3:36 PM, bearophile wrote: > lijie: > > > import std.stdio; >>> void main() { >>> void delegate()[] functions; >>> foreach (i; 0 .. 5) { >>> functions ~= { >>> printf("%d\n

A delegate problem, create delegation in loop

2012-07-04 Thread lijie
Hi, My test code: > import std.stdio; > void main() { > void delegate()[] functions; > foreach (i; 0 .. 5) { > functions ~= { > printf("%d\n", i); > }; } > foreach (func; functions) { > func(); > } > } output: $ dmd DMD64 D Compiler v2