Comments (6)
Hello @trrahul.
No the output is right.
This because a variable contains a C# object and in your case. variables c
and d
contains a string
. So they are interpreted as string
.
So if you do this :
evaluator.Evaluate("c+d");
// or if
evaluator.Variables["h"] = "Hello";
evaluator.Variables["w"] = "World";
evaluator.Evaluate("h+\" \" +w");
you get :
a+bc+3
Hello World
but if you want to evaluate a string in a evaluation you could do something like this :
evaluator.Evaluate("Evaluate(c)");
evaluator.Evaluate("Evaluate(d)");
And then you will get :
3
6
See Custom variables and Functions for more infos
from expressionevaluator.
After a little thought. I think it might be good to introduce a type of variable that could be evaluated when encountered to better answer to this issue.
Something like :
evaluator.Variables["c"] = new SubExpression("a+b");
evaluator.Variables["d"] = new SubExpression("c+3");
I Reopen this issue and will work on it for the next version of ExpressionEvaluator.
So @trrahul thanks for this issue.
from expressionevaluator.
Isn't it better to search for the variables in the expression and evaluate them in order instead of creating a new subexpression?
Because in this case, please correct me if I am wrong, every variable has to be created as a subexpression if they are used later in another expression.
from expressionevaluator.
You need to understand that variables are just containers like C# variables or any programming language variables. It could contains anything (string, int, float, Regex, File or a custom class...) and a string
is not a expression it's a string
and it's right like this because you can do operation with string
variables so you need a specific type to specify that the content of a variable must be evaluate otherwise the variable is simply evaluated as it's content.
Because in this case, please correct me if I am wrong, every variable has to be created as a subexpression if they are used later in another expression.
No if a variable is just a value like your variables a
or b
(int) they are interpreted as this.
So only variables that need to be evaluated when met need to be contains in a specific type that ExpressionEvaluator know it' need to be sub evaluate.
But of course if you also encapsulate a
and b
with subexpression it will also work. Because the subevaluation will return their values.
from expressionevaluator.
Thanks for the clarification. I was trying out different expression evaluators and this issue happened with all the libs I tried except lambdaparser. It was able to evaluate the expression correctly, but it had another problem ExpressionEvaluator did not have. nreco/lambdaparser#22
from expressionevaluator.
I just published version 1.4.9.0 that allow to the use of SubExpression here is the doc on the wiki SubExpression variable
from expressionevaluator.
Related Issues (20)
- Add an option to disallow accessing namespaces HOT 2
- Referencing property of property can cause unwanted exception
- Syntax error of sign symbols
- Intelligente type casting
- Error message - Exception has been thrown by the target of an invocation. HOT 3
- Linq Select throws exception (ValueTuple?) issue? HOT 3
- Syntax error in Functions HOT 3
- Incorrect result. HOT 1
- Strong name HOT 1
- Ignore missing zero in numeric values
- Match function arguments considering implicit casts HOT 2
- Decimal support for math functions
- Slow EvaluateCast HOT 1
- Syntax error calling overloaded method in context object including Func<> parameter
- Link error in Unity Android il2cpp build
- Can't handle division HOT 2
- [Suggestion] AssignVariable in Script Evaluation (Not in Declraration)
- Doesn't process a IDictionary<string, object> correctly.
- Is it possible to add an operator that is both right-hand-side-only and can act as a normal one? HOT 2
- RobiniaDocs API Explorer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expressionevaluator.