Here's a future implementation: //////////// var ch = mk_schannel[int](); spawn_fthread { write (ch,42); }; var x:int; var flag = false; proc fetch() { x = read ch; flag = true; }
gen get() = { if not flag do fetch; done return x; } println$ #get; ///////////// The big problem is the generator get: this program only works "by luck" because it is inlined. It fails (with a segfault) if it isn't because read is only allowed in a zero machine stack context. To be more certain we could write: inline gen get ... But you can still make a closure (which ensures failure), of make a recursive generator (which can't be inlined). Felix current doesn't detect these errors. There *is* a trick to encourage inlining: use a C binding. This still doesn't prevent closure formation. The core problem is that functions use the machine stack, and inlining is the only way to get rid of it. The compiler actually has a routine the replaces functions with procedures, to allow more code like the above to work (even if the procedure isn't inlined, its OK: procedures don't use the machine stack). But of course this cannot handle assigning a closure to a variable (because a variable of function type has to have an actual machine stack using closure in it). Apart from C compatibility and performance there's a rather lame implementation reason to use functions: they can return values. This means you can have expressions. Without this, one has to break code down to three-address form: x = a1 op a2 and implement that procedurally. This is a pain because the Felix optimiser works best analysing expressions because they're simple terms: sequences (lists) of instructions are not, they're much harder to pattern match on. -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Monitor your physical, virtual and cloud infrastructure from a single web console. Get in-depth insight into apps, servers, databases, vmware, SAP, cloud infrastructure, etc. Download 30-day Free Trial. Pricing starts from $795 for 25 servers or applications! http://p.sf.net/sfu/zoho_dev2dev_nov _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language