Getting an exception when trying to use lazy variables
HussamHallak opened this issue · 4 comments
I tried running the lazy variables usage example in the readme file. I got this exception:
Exception in thread "main" java.lang.NumberFormatException: Non-numeric character in input 'x + 1'
at redempt.crunch.data.FastNumberParsing.parseDouble(FastNumberParsing.java:85)
at redempt.crunch.ExpressionCompiler.compileToken(ExpressionCompiler.java:245)
at redempt.crunch.ExpressionCompiler.compileValue(ExpressionCompiler.java:73)
at redempt.crunch.ExpressionCompiler.compile(ExpressionCompiler.java:32)
at redempt.crunch.Crunch.compileExpression(Crunch.java:22)
at CrunchDemo.main(CrunchDemo.java:10)
Able to reproduce by not supplying the EvaluationEnvironment holding the lazy variable when compiling the expression. This is an issue on your end; I've added a test case for the exact input, supplying the EvaluationEnvironment, and it passes.
I should have included my code. Is there any code that I need to add that I might be missing?
import redempt.crunch.CompiledExpression;
import redempt.crunch.Crunch;
import redempt.crunch.functional.EvaluationEnvironment;
public class CrunchDemo {
public static void main(String[] args) {
EvaluationEnvironment env = new EvaluationEnvironment();
env.addLazyVariable("x", () -> 4);
CompiledExpression exp = Crunch.compileExpression("x + 1");
exp.evaluate(); //This will return 5
}
}
Yes, you need to pass the EvaluationEnvironment to compileExpression. Looks like the readme is wrong, thanks for bringing that to my attention.
Thank you.