Next article: Friday Q&A 2009-10-30: Generators in Objective-C
Previous article: Friday Q&A 2009-10-16: Creating a Blocks-Based Object System
Tags: fridayqna generators
I'm afraid that I ran out of time this week and wasn't able to put together a real Friday Q&A. However, as a preview of what I'll be talking about next week, check out the MAGenerator project in my public subversion repository.
MAGenerator is a library for building generators in Objective-C. These are much like the generators found in Python, although with a slightly different interface. They are essentially functions which remember state between invocations, such that when you call them a second time, all local variables have the same value they did at the end of the first call, and execution resumes where it was when it returned from the first call.
There's complete, if terse, documentation found in the MAGenerator.h
header, and some examples in the GeneratorTests.m
file. I plan to release the code under an MIT license if you'd actually like to use it somewhere. Unlike my blocks-based object system from last week, I think this code could actually be used in a practical sense, even though the implementation is still pretty much evil.
Next week I'll go through how it all works, why it's built the way it is, and how to use it. Until then, enjoy the code. And as always, keep your suggestions for topics coming. I'm already booked for next week but am always happy to hang on to ideas for later.
Comments:
Next week will be the full discussion of how it works and what they're good for. In the mean time, I suggest the following light reading:
http://en.wikipedia.org/wiki/Generator_(computer_science)
http://en.wikipedia.org/wiki/Coroutine
http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
And whatever discussion of generators in Python (a language that has had built-in support for them for a long time) you can turn up.
Comments RSS feed for this page
Add your thoughts, post a comment:
Spam and off-topic posts will be deleted without notice. Culprits may be publicly humiliated at my sole discretion.