Yigal Chripun Wrote: > On 25/10/2009 06:26, Jason House wrote: > > > My web search and some PDF's didn't turn up a handy example. You can > > do things in scala like define your own foreach loop. If foreach had > > the form form foreach(x){y} then x would be one set of arguments and > > y would be another set. It makes for pretty use of library functions. > > They look built in! > > > > isn't that similar in concept to code blocks?
I'm not familiar enough with code blocks to say for sure. From what I saw in blogs, they are not. Either way, D can't make things look built in like scala can. IMHO, it's a great programming language feature. > > I looked over the links (quickly). I must admit I don't get it yet. > > It takes me a while to digest lisp fragments... Can you give a D-ish > > example of what it'd look like? > > > > > here's a Nemerle example: > > macro PrintStage() { > System.Console.WriteLine("This is executed during compilation"); > <[ System.Console.WriteLine("This is executed at run time") ]> > } > > the first WriteLine is executed during compilation, and the macro > returns the AST for the second WriteLine which will be executed at run > time when this macro is called. How is that different from a normal function definition that includes some compile-time calls? I agree that compile-time code should look and feel like normal code. It seems you use macro to switch to compile-time by default and runtime when explcitly marked? Having both defaults (compile time or run time) makes sense. > one important design goal is to clearly separate the stages, so this > will go to a separate .d file and will be compiled into a lib. > to use this macro you simply specify > compiler --load-macro=myMacro sources.d > > in user code you just use "print();" I disagree with this. The code that uses the macros should declare what it uses. > > OK, here's an example: > > class Foo { > int a; > void bar(); > } > > auto obj = new Foo; > obj.a = 42; // obj contains a > obj.bar(); // calls 'Foo.vtbl.bar > > remember that 'Foo is the classinfo singelton for Foo > > class Foo { > static a; > static void bar(); > } > > Foo.a = 42; // 'Foo contains a > Foo.bar(); // calls ''Foo.vtbl.bar > > ''Foo is the classinfo singelton for 'Foo > > we get the following chain ("-->" means instance of) > obj --> Foo --> MetaFoo --> MetaClass --> Class > > compared with C++/D/Java/etc: > obj --> Foo --> Class Ok. That makes sense. It can be simplified when statics are removed.