Take care! There is a bug in the compiler causing
test/regress/rt/generators-01.flx to fail. When I looked at the test I saw the problem instantly. Here's the code: /////////////////////////////////////////////////////// //Check generators var cheat : int = 0; gen f():int = { ++cheat; //print "Generator "; print cheat; endl; return cheat; } print "F 1="; print$ f(); endl; // 1 body """ static int x = 0; int g() { ++x; return x; } """; gen g : 1 -> int; print "C 1="; print$ g(); endl; // 1 fun d(x:int) => x + x; // all these should be even print "F Even? "; print$ d(f()); endl; // 4 print "F Even? "; print$ d(f()); endl; // 6 print "C Even? "; print$ d(g()); endl; // 4 print "C Even? "; print$ d(g()); endl; // 6 print "F 4="; print$ f(); endl; // 4 print "C 4="; print$ g(); endl; // 4 ///////////////////////////////////////////////// and the output: F 1=1 C 1=1 F Even? 4 F Even? 6 C Even? 5 C Even? 9 F 4=4 C 4=6 Obviously, C is wrong: 5 and 9 are not even! Should read 4 and 6! The problem is simple: the primitive generator g() is wrapped in a plain (non-generator) function. Since that function isn't marked as a generator as it should be, the x+x is replaced by the wrapper in both cases of x. Were the wrapper of g ALSO marked as a generator it would be hauled out of the expression and assigned ONCE to a variable which is then added to itself. So the bug is simple: the wrapper of a primitive should inherit the primitives generator attribute. Easy fix. But this suggests I issue a warning! Generator have side effects and they can NOT be nested in a function, only in a generator or procedure (except in special circumstances where you can prove it is harmless). -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language