pub struct TermBuilder<I, C> { /* private fields */ }
Expand description
This can be used to construct a term from a given input of (inductive) type I, without using the system stack, i.e. recursion. See evaluate.
Implementations§
Source§impl<I: Debug, C: Debug> TermBuilder<I, C>
impl<I: Debug, C: Debug> TermBuilder<I, C>
pub fn new() -> TermBuilder<I, C>
Sourcepub fn evaluate<F, G>(
&mut self,
tp: &mut TermPool,
input: I,
transformer: F,
construct: G,
) -> Result<ATerm, Box<dyn Error>>
pub fn evaluate<F, G>( &mut self, tp: &mut TermPool, input: I, transformer: F, construct: G, ) -> Result<ATerm, Box<dyn Error>>
This can be used to construct a term from a given input of (inductive) type I, without using the system stack, i.e. recursion.
The transformer
function is applied to every instance I, which can put
more generate more inputs using a so-called argument stack and some
instance C that is used to construct the result term. Alternatively, it
yields a result term directly.
The construct
function takes an instance C and the arguments pushed to
stack where the transformer was applied for every input pushed onto the
stack previously.
§Example
A simple example could be to transform a term into another term using a
function f : ATerm -> Option<ATerm>
. Then I
will be ATerm since that is
the input, and C
will be the Symbol from which we can construct the
recursive term.
transformer
takes the input and applies f(input). Then either we
return Yield(x) when f returns some term, or Construct(head(input)) with
the arguments of the input term pushed to stack.
construct
simply constructs the term from the symbol and the arguments
on the stack.
However, it can also be that I is some syntax tree from which we want to construct a term.