Loge: Prolog smoke test
root = Path.expand("..", __DIR__)
Mix.install([
{:loge, path: Path.join(root, "loge"), override: true},
{:loge_prolog, path: Path.join(root, "loge_prolog")},
{:kino_loge, path: Path.join(root, "kino_loge")}
])
Solving
Expected: Yes, a table with Z = ann and pat.
Loge.run!(
Loge.Prolog.Engines.Swipl,
"parent(tom, bob).\nparent(tom, liz).\nparent(bob, ann).\nparent(bob, pat).\n\ngrandparent(X, Z) :- parent(X, Y), parent(Y, Z).\n\n?- grandparent(tom, Z).\n",
answers: 0,
time_limit: 10
)
Expected: No, no table.
Loge.run!(
Loge.Prolog.Engines.Swipl,
"parent(tom, bob).\nparent(tom, liz).\nparent(bob, ann).\nparent(bob, pat).\n\ngrandparent(X, Z) :- parent(X, Y), parent(Y, Z).\n\n?- grandparent(ann, _).\n",
answers: 1,
time_limit: 10
)
What the program prints is the Output tab. Expected: Yes, Output hello, world.
Loge.run!(
Loge.Prolog.Engines.Swipl,
"greet(Name) :- format(\"hello, ~w~n\", [Name]).\n\n?- greet(world).\n",
answers: 1,
time_limit: 10
)
Expected: Timeout after two seconds.
Loge.run!(Loge.Prolog.Engines.Swipl, "loop :- loop.\n\n?- loop.\n", answers: 1, time_limit: 2)
Includes
A Logic Source cell binds the program to family; a cell that consults it with
:- [family]. asks a query of its own. Expected: Yes, Z = ann and pat.
family =
Loge.source(
:prolog,
"parent(tom, bob).\nparent(tom, liz).\nparent(bob, ann).\nparent(bob, pat).\n\ngrandparent(X, Z) :- parent(X, Y), parent(Y, Z).\n"
)
Loge.run!(Loge.Prolog.Engines.Swipl, ":- [family].\n\n?- grandparent(tom, Z).\n",
answers: 0,
time_limit: 10,
includes: %{"family" => family}
)
Linting
Expected: under the editor, Y is a singleton (warning, on Y) and line 3 has a syntax
error; evaluating raises Loge.Error with the syntax error.
Loge.run!(Loge.Prolog.Engines.Swipl, "p(X) :- q(X, Y).\nq(a, b).\nr( :- s.\n\n?- p(a).\n",
answers: 1,
time_limit: 10
)