Macro swipl_macros::term
source · term!() { /* proc-macro */ }
Expand description
Generate a term from a rust expression.
This macro takes two arguments, a context to generate the term in, and a rust expression representing the prolog term to generate..
The macro returns a PrologResult<Term>
containing new term,
created through context.new_term_ref()
, which contains a prolog
term corresponding to the description. The term!
macro cannot
actually fail with a PrologFailure, but it is possible for a
resource limit exception to be triggered by one of the underlying
calls into prolog.
Examples
Generate a nested functor term:
ⓘ
let term = term!{context: foo(bar(baz, quux))}?;
Embed a value in the term:
ⓘ
let num = 42;
let term = term!{context: foo(#42)}?;
Embed a term in the term:
ⓘ
let inner = context.new_term_ref();
let term = term!{context: foo(#&inner)}?;