View Source Guesswork.Ast (Guesswork v0.8.0)
Helper tools/macros for building rules and statements.
Summary
Functions
Creates a Guesswork.Ast.Fact
that allows the use of variables.
Builds a Guesswork.Ast.Is
using a fn
.
Creates a Guesswork.Ast.Rule
that, like term
, allows the use of variables.
Allows a Guesswork.Ast.Term
to be built with variables.
Functions
Creates a Guesswork.Ast.Fact
that allows the use of variables.
Builds a Guesswork.Ast.Is
using a fn
.
Note that this cannot be used in a Guessork.KnowledgeBase.Collection
.
Instead Guesswork.Ast.Is.new/3
will have to be used directly with a function
caputured using &Mod.fun/arity
.
Creates a Guesswork.Ast.Rule
that, like term
, allows the use of variables.
Allows a Guesswork.Ast.Term
to be built with variables.
Note that, like ecto queries, external values and elixir expressions can be
injected by using the pin operator (^
).
Examples
iex> Guesswork.Ast.term(b)
Guesswork.Ast.Variable.new("b")
iex> Guesswork.Ast.term(Guesswork.Ast.Fact.new("test", [a, :b]))
Guesswork.Ast.Fact.new("test", [Guesswork.Ast.Variable.new("a"), :b])
iex> a = 45
...> Guesswork.Ast.term(Guesswork.Ast.Fact.new("test", [^a, :b]))
Guesswork.Ast.Fact.new("test", [45, :b])