I'm making a framework for specifying processes which may involve choices. I've got it working where each choice is an island. I'd prefer that subchoices 'fork' the parent choice, so that all options are properly considered.
choose :one => lambda {
choose [a, b]
if a
raise "Illegal"
end
},
:two => ....
Currently, it would always choose 'a' (which taken by itself looks better) but causes problems further down. Action :one with option 'b' is never considered.
I've run across callcc (not portable to all Ruby implementations, from what I've read) and fibers (new in 1.9 and can't be assumed to be available) as things that might be convinced to work, but I'm not crazy about having two implementations, or about the black magic of either of them, really.
I ended up taking the easy way out and passing the remainder of the computation as a block. This became a little less painful when I saw a similarity to an existing structure. I'm just hoping the indents don't get out of line.
The real case is significantly more complicated - there are side effects, but they are contained in a versioned key-value store. I'm also enumerating all possibilities and choosing the best one, so it can't just stop on success.