Sequence generators
Posted: January 23rd, 2012 | Author: Mars | Filed under: Uncategorized | Comments OffI’ve done some work on the asynchronous sequence and task scheme and perhaps a quarter of the job is finished. I started with generators, as they are a bit simpler than tasks, and have implemented the generator block structure and the yield statement. The compiler can break a block down into what is effectively a series of callbacks, and represent that as a sequence-type object. It’s neat to watch it work.
The next step is to implement a delegating yield from statement. This is important because the compiler will recursively decompose control-flow blocks like if statements and loops into sub-generators; it will the internally “yield from” these sub-generators, thus allowing you to place yield statements inside these nested blocks – an important part of the system!
This whole asynchronous-callback scheme is a pretty big job but I think it is worth the effort. Sequence generator functions will be a big addition to the language; sequences are the whole point of Radian, really, and you can think of the generator block as being the converse of a for-loop. The new IO system is obviously a bit more syntactically involved than the monadic IO system, but I think it will be more approachable. I expect that it will be substantially easier to figure out how to compose complex operations with it. And while the task block is intended primarily for IO, I’m sure people will find many other interesting things to do with it.