Basically, here's what TraderMissions code for handling a dialog would look like, if TM was in Ruby:
# Called every time this state becomes
# the active one.
def activate
if @dialog.yes?
do_things
end
if @other_dialog.stuff?
do_other_things
end
end
The activate function has to check every possible state that it might transition into, see if it was called and if so what its result was, and deal with that. This rapidly becomes horrible. Whereas with continuations:
def activate
@continue.call if @continue
end
And that's set up when I originally transition to the other state:
def verify_cheese
cv = CheeseVerifier.new
callcc do | cont |
@continue = cont
@driver << cv
end
enable_cheese if cv.yes?
end
@continue.call moves execution back to after the block where I originally set @continue, thus letting me pick up where I had transitioned away from the current state. Hooray for continuations!
Oh, right, the subject. I'd actually done that continuation stuff months ago, the Waker thing was me moving it. Most of the day was me creating a simple object selector. I thought to myself "I need a MiniBuilder equivalent for those children which only have one object. Thus:
THE MINICHOOSER!
No comments:
Post a Comment