Skip to content

Instantly share code, notes, and snippets.

@christianromney
Created October 26, 2017 14:21
Show Gist options
  • Save christianromney/2a0ed3b61f59210a65123c85c4c276b8 to your computer and use it in GitHub Desktop.
Save christianromney/2a0ed3b61f59210a65123c85c4c276b8 to your computer and use it in GitHub Desktop.
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