Guesswork - Logic programming for Elixir

Guesswork is a logic programming library for Elixir. Its based heavily on Prolog, but I’ve attempted to make it follow more idiomatic Elixir where it makes sense (for instance, queries are resolved into a Stream of possible solutions). Its still rather rough, but should fully support knowledge bases, recursive statements, and all basic logical operations.

The plan moving forward is to add support for constraints and add more optimizations for how queries are resolved.

The best place to read about it are the docs and the gitlab repo:

9 Likes

Why deffact use so strange format of deffact("foo", [a, b]) instead of more “natural” deffact foo(a, b)?

You’re right, that’s a much better syntax, and its a change I’d like to make. I just haven’t figured out that part of building macros yet (I think I have an issue for that in gitlab, if not I’ll add one).

Hint, in IEx you can use quote to see AST, for example:

iex> quote do
...>   deffact foo(a, b)
...> end
{:deffact, [],
 [
   {:foo, [],
    [
      {:a, [], Elixir},
      {:b, [context: Elixir, imports: [{1, IEx.Helpers}]], Elixir}
    ]}
 ]}

And now you see that foo(a, b) will be passed as just regular function call (that is the reason why you can do stuff like def a + b in Elixir).

3 Likes

It also looks like I can use Macro — Elixir v1.16.3 too handle those expressions pretty easily. I’ll just need to change the type for Fact some.