Term types used in Datalog atom arguments.
A term is one of:
- A logic variable:
{:var, name}— matches any value and binds it toname. - A constant:
{:const, value}— a ground value (integer, string, or atom). - A wildcard:
:wildcard— an anonymous variable that matches any value without binding.
Examples
iex> ExDatalog.Term.var("X")
{:var, "X"}
iex> ExDatalog.Term.const(:alice)
{:const, :alice}
iex> ExDatalog.Term.const(42)
{:const, 42}
iex> ExDatalog.Term.wildcard()
:wildcard
Summary
Functions
Constructs a constant term.
Returns true if the term is a constant.
Returns true if the term is a valid ExDatalog.Term.t().
Constructs a logic variable term.
Returns true if the term is a logic variable.
Returns all variable names present in a list of terms.
Constructs an anonymous wildcard term.
Returns true if the term is a wildcard.
Types
Functions
Constructs a constant term.
Accepts integers, strings, and atoms. Floats are not supported — Datalog
relations use discrete values. If you pass a float, const/1 raises
ArgumentError.
Note that true, false, and nil are valid Elixir atoms and are
accepted as constants, producing {:const, true}, {:const, false},
and {:const, nil} respectively. Use these with care — nil in
particular may be confused with an absent value downstream.
Examples
iex> ExDatalog.Term.const(:alice)
{:const, :alice}
iex> ExDatalog.Term.const(42)
{:const, 42}
iex> ExDatalog.Term.const("hello")
{:const, "hello"}
Returns true if the term is a constant.
Examples
iex> ExDatalog.Term.const?({:const, :alice})
true
iex> ExDatalog.Term.const?({:var, "X"})
false
iex> ExDatalog.Term.const?(:wildcard)
false
Returns true if the term is a valid ExDatalog.Term.t().
Examples
iex> ExDatalog.Term.valid?({:var, "X"})
true
iex> ExDatalog.Term.valid?({:const, 42})
true
iex> ExDatalog.Term.valid?(:wildcard)
true
iex> ExDatalog.Term.valid?(:bad)
false
Constructs a logic variable term.
Examples
iex> ExDatalog.Term.var("X")
{:var, "X"}
iex> ExDatalog.Term.var("ParentNode")
{:var, "ParentNode"}
Returns true if the term is a logic variable.
Examples
iex> ExDatalog.Term.var?({:var, "X"})
true
iex> ExDatalog.Term.var?({:const, :alice})
false
iex> ExDatalog.Term.var?(:wildcard)
false
Returns all variable names present in a list of terms.
Examples
iex> ExDatalog.Term.variables([{:var, "X"}, {:const, :alice}, {:var, "Y"}, :wildcard])
["X", "Y"]
@spec wildcard() :: :wildcard
Constructs an anonymous wildcard term.
A wildcard matches any value but does not bind it to a name. Wildcards may appear in rule bodies but not in rule heads.
Examples
iex> ExDatalog.Term.wildcard()
:wildcard
Returns true if the term is a wildcard.
Examples
iex> ExDatalog.Term.wildcard?(:wildcard)
true
iex> ExDatalog.Term.wildcard?({:var, "X"})
false