Best way to evaluate expressions

Oct 26, 2007 at 12:11 AM
Edited Oct 26, 2007 at 12:12 AM
Hey guys,

I've been thinking about the current way that expressions are evaluated (using the ExpressionEvaluator delegate) and I want to find a way to improve it and make it cleaner. I don't like exposing the expression's delegate and requiring two steps for evaluation.

The problem is that you have to be able to evaluate an expression to a strongly typed result (for performance) as well as to an Object (for dynamic scenarios). The best way I can think of doing this is to have a base Expression class that has an Evaluate method which returns an Object and then have a derived generic class that would have a strongly typed Evaluate.

What do you guys think? Is there a better way or is the current method good enough?
Oct 26, 2007 at 10:39 AM
I think that it is important to keep 2 steps: one step for expression compilation and one step for evaluation.

You can create a generic class Expression<TOwnerType, TResultType> with a Method TResultType Eval(TOwnerType owner)
Oct 27, 2007 at 11:16 PM
Your other post has given me an idea of how to refactor Flee to make it better. It will be a big change and will break old code but in the end Flee will be much more powerfull and flexible.
Nov 1, 2007 at 1:46 PM
Hi, after a couple of moths i go back to my (flee-dependent) project...

I like the words -> "refactor"->"make it better" of course they are relatives but flee is stable enough to do this, if some people have some implementation with the old code they can continue with this until can migrate to a new Flee.

At least is my case i will be happy to see good refactoring and implement it in my project.

Just support words ;-)

Nov 2, 2007 at 1:25 AM
Nov 6, 2007 at 1:16 AM
I've made the changes in Flee- Hopefully they will make Flee easier to use while also making it more flexible and dynamic.
Nov 28, 2007 at 2:19 PM
Having a way to create flee object as follows would be great:

CalcEngine calc = new CalcEngine();

FleeAtom atomAB = calc.Atoms.get_atom("AB");

FleeAtom atomA = calc.Atoms.get_atom("A");

FleeAtom atomB = calc.Atoms.get_atom("B");

atomA.EnterValue = 1;

atomB.EnterValue = 1;

atomAB.Formula = "A+B";

// If we check atomAB.Value it will be 2

AtomA.EnterValue = 3;

// If we check atomAB.Value it will be 3

This would make Flee very easy to work with.

Nov 28, 2007 at 8:09 PM

The last comment should have been:

// If we check atomAB.Value it will be 4

Dec 5, 2007 at 1:31 AM
Good to see a different way of approaching it. Thanks.