Skip to content

Instantly share code, notes, and snippets.

@srenatus
Created October 12, 2020 08:05
Show Gist options
  • Save srenatus/49ae9ed2706a4592ef372dce627ad227 to your computer and use it in GitHub Desktop.
Save srenatus/49ae9ed2706a4592ef372dce627ad227 to your computer and use it in GitHub Desktop.
require 'oso'
$polar=<<POLAR
add(x: String, y: String, x.concat(y));
add(x: List, y: List, x.concat(y));
add(x: List, y: String, x0.concat(y)) if x0 in x;
add(x: String, y: List, x.concat(y0)) if y0 in y;
POLAR
class Example
def initialize
@o = Oso.new
@o.load_str($polar)
end
def method_missing(m, *args, &block)
z = Oso::Polar::Variable.new('z')
args.append(z)
@o.query_rule(m, *args).map {|b| b['z']}
end
end
e = Example.new
raise unless e.add("foo", "bar").to_a == ["foobar"]
raise unless e.add(["foo"], "bar").to_a == ["foobar"]
raise unless e.add("foo", ["bar", "baz"]).to_a == ["foobar", "foobaz"]
raise unless e.add(["foo"], ["bar", "baz"]).to_a == [["foo", "bar", "baz"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment