Created
October 26, 2017 14:21
-
-
Save christianromney/2a0ed3b61f59210a65123c85c4c276b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "continuation" | |
$breadcrumbs = [] | |
def current_continuation | |
callcc { |cc| cc } | |
end | |
def fail! | |
raise "No more breadcrumbs to follow" if $breadcrumbs.empty? | |
next_stop = $breadcrumbs.pop | |
next_stop.call next_stop | |
end | |
def amb(*choices) | |
current_stop = current_continuation | |
if choices.empty? | |
fail! | |
else | |
$breadcrumbs.push current_stop if current_stop | |
choices.shift | |
end | |
end | |
def assert!(cond) | |
unless cond | |
fail! | |
else | |
true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment