View Source Guesswork.Ast (Guesswork v0.6.0)

Helper tools/macros for building rules and statements.

Summary

Functions

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

Link to this macro

is(binding, func)

View Source (macro)

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.

Link to this macro

rule(name, args, expr)

View Source (macro)

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])
iex> Guesswork.Ast.term(Guesswork.Ast.Fact.new("test", [:_, :b]))
Guesswork.Ast.Fact.new("test", [%Guesswork.Ast.Wildcard{}, :b])