Higher Order Blog

home

Fibers: an exercise

15 Aug 2008

I was involved with arranging and hosting the RubyFools 2008 conference (it was a great conference btw). One of my jobs was to come up with a bunch of Ruby exercises for our Ruby cave. I decided to go with exercises on the new Ruby 1.9 Fiber class since it is new and because I'm interested in concurrency. One of the exercises was a tricky exercise which, as far as I know, nobody solved. Now whether that was because no one tried or cared, or because it was too tricky, I don't know. In either case, I think it is a pretty neat exercise. Here it is. Exercise. Using only the Fiber class from Ruby 1.9, write a class FiberStack which is an implementation of the Stack data structure. You can't use any heap memory (except for Fiber), so using arrays or linked objects is out of the question. Please don't paste code into comments. Instead post solutions as a comment here. Then post a comment here linking to that solution. In this way we won't spoil the fun for those wanting to solve it on their own.