The expression adds one to the supplied x value. Parse the expression and input separately, build the program once, and evaluate it with a native document. The input and result remain documents until you choose to serialize them.
Build an expression and evaluate it
expressionText holds this document:
[+ ?x 1]
inputText holds this document:
x 41
expression, err := stardust.Parse(expressionText, stardust.DUST)
if err != nil {
return err
}
defer expression.Close()
input, err := stardust.Parse(inputText, stardust.DUST)
if err != nil {
return err
}
defer input.Close()
program, err := stardust.Build(expression, nil)
if err != nil {
return err
}
defer program.Close()
result, err := program.Evaluate(input, nil)
if err != nil {
return err
}
defer result.Close()42
The captured result is 42. Release the result, program and parsed documents when finished. A retained program can evaluate further inputs. See Expressions and macros.