So now I have changed the topic, but we go on having fun with active programming. Examine this:
// First, we make a tee procedure. proc run_tee[T] (i:ischannel[T], o1:oschannel[T], o2:oschannel[T]) { again:> var d = read i; write (o1, d); write (o2, d); goto again; } // Now, we make a procedure that connects a source device // to two transducers by tee'ing the output from the source. // // The result of this is two new sources which can be used // to start new pipelines. fun tee[T,U] ( w:oschannel[T] -> 0, t1:ischannel[T] * oschannel[U] -> 0, t2:ischannel[T] * oschannel[U] -> 0 ) : (oschannel[U]->0) * (oschannel[U]->0) = { var i,o = #mk_ioschannel_pair[T]; var chi1,cho1 = #mk_ioschannel_pair[T]; var chi2,cho2 = #mk_ioschannel_pair[T]; spawn_fthread { w o; }; spawn_fthread { run_tee (i,cho1, cho2); }; return proc (out:oschannel[U]) { spawn_fthread { (t1 (chi1, out)); }; }, proc (out:oschannel[U]) { spawn_fthread { (t2 (chi2, out)); }; } ; } // test sink proc sink (i:ischannel[string]) { while true do println$ read i; done } // test source proc src (o:oschannel[string]) { for line in ("Hello", "World", "Again", "Jupiter") do write (o, line); done } // test transducer (prepends line with an integer identifier) proc xduce (x:int) (i:ischannel[string], o:oschannel[string]) { while true do write (o, str x + " : " + read i); done } //spawn_fthread$ src |-> xduce 1 |-> sink; var s1, s2 = tee (src, xduce 1, xduce 2); spawn_fthread$ s1 |-> sink; spawn_fthread$ s2 |-> sink; //////////////////////////////////////////// 1 : Hello 2 : Hello 1 : World 2 : World 1 : Again 2 : Again 1 : Jupiter 2 : Jupiter //////////////////////////////////////////// Unfortunately I think this is still not right. The reason is that the tee function actually starts the source and the tee running. So now, here'\s some FUN. In data theory some wag (Knuth? Wirth?) said this: "All problems in computing can be solved by adding an extra level of indirection" So if you stuff up in C, just add some stars! With active programming, however this becomes: "All problems in active programming can be solved by adding an extra level of laziness" Which means, in Felix, adding and extra () parameter to your function!! -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial Remotely access PCs and mobile devices and provide instant support Improve your efficiency, and focus on delivering more value-add services Discover what IT Professionals Know. Rescue delivers http://p.sf.net/sfu/logmein_12329d2d _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language