Extensions for Flee

Aug 7, 2007 at 9:31 PM
Some extensions to Flee,

  • handle variables of Datetime type
  • create variables dynamically
  • handle assign of variables ; var = expr
  • allow to evaluate a list of Expressions
  • allow to obtain results from the context of the evaluator
  • allow for,while,repeat

Aug 9, 2007 at 1:31 AM
handle variables of Datetime type
Do you mean support the predefined operators on the DateTime type? I've been meaning to add support for predefined operators for all types.

create variables dynamically
Ahh yes, the new operator. It's also on my list.

handle assign of variables ; var = expr
allow for,while,repeat
I think these features break away from expressions and towards full-blown programming language. Can you give me a use case?

allow to obtain results from the context of the evaluator
You can access any members of the ExpressionOwner. Can you clarify what this means?

Aug 17, 2007 at 1:28 PM
Hi i like to add:

allow to evaluate a list of nested Expressions, something like

Expression IVApct = new Expression('0.21')

Expression SubTotal = new Expression('100')

Expression Total = new Expression('SubTotal * IVApct')


Maybe a new high level class to handle this...
Aug 17, 2007 at 2:31 PM
I'm going to implement something like this on the weekend. It will also track dependencies between the expressions and allow you to recalculate in natural order.
Aug 17, 2007 at 4:02 PM

Probably the idea of dynamic Variables and assign to those variables, tends to a language of script.

Nevertheless it would be highly valuable to count thus on an extension that allows to evaluate expressions list:

By example;


Where: A , B, C are variable dynamics they do not come from an ExpressionOwner instance.


valueA = ExprEngine<double>.GetValue("A");
valueB = ExprEngine<double>.GetValue("B");
valueC = ExprEngine<double>.GetValue("C");

I hope that it is not much to request.

Thank you very much;
Aug 20, 2007 at 2:00 AM
Hi guys,

The release has just been posted. It implements dynamic variables and a calculation engine that allows you to reference other expressions in an expression. It isn't documented yet but there is an example on the Examples page that shows how to use it.

Aug 20, 2007 at 2:54 PM
Edited Aug 20, 2007 at 2:58 PM

Excellent improvement, thank you very much.

I thought about an extension like the following one:

ExpressionOwnerDynamic exprVars ;

exprVars.AddVariable( "X", typeof(double) );
exprVars.AddVariable( "Y", typeof(int) );

In the background , do its:

Type baseClass = typeof ( ExpressionOwner ) ;
TypeBuilder typeBuilder = moduleBuilder.DefineType(
TypeAttributes.Public | TypeAttributes.Class |
TypeAttributes.BeforeFieldInit, baseClass ) ;

DefineType allows you to specify type attributes for the generated type. In this case, the new type is a class; it has public visibility (and static members can be called without forcing the runtime to initialize the class).

The name, type, and attributes are specified in a single call. The following code snippet shows how it looks:

// Create a public field for variables
FieldBuilder doubleField = typeBuilder.DefineField(
"X", typeof( double ) ,
FieldAttributes.Public ) ;

FieldBuilder doubleField = typeBuilder.DefineField(
"Y", typeof( int ) ,
FieldAttributes.Public ) ;


This allows to create a class/structure, dynamically accessible by Flee.

An idea is single, as soon as can put it in practices, I inform to him.

In addition, it does not change the architecture of Flee.

Thank you very much.

Aug 20, 2007 at 5:15 PM

You're right. It's more useful to be able to have variables of various types in one owner. I will make the change tonight (if I have time).

Aug 20, 2007 at 5:31 PM
Edited Aug 20, 2007 at 5:34 PM

Thank you very much, by your attention.

If you it makes this improvement, would be to me very useful for a scenario in where from metadata into the database, I can describe user algorithms of calculations.

Aug 21, 2007 at 2:48 AM

I've refactored the DynamicExpressionOwner to support variables of different types. I updated the files in instead of creating a new release so you can just re-download to get the changes.

Aug 21, 2007 at 3:52 AM
Edited Aug 21, 2007 at 4:02 AM
Hi Eugene,

Excellent refactroing, thank you very much

I think about the following :

I can to persist IL Generated in a file (in raw bytecode), this could be reloaded by Flee without reparsing ?


I can be serialize the AST to XML (by example), after recover it and save parsing time ?

I think in an long set of calculations.

Aug 21, 2007 at 3:58 PM
Saving the raw IL has two problems:
-There is no straightforward way to get the IL of a dynamic method once created
-The IL contains tokens whose values are determined at runtime. So the saved value of a token is meaningless when the IL is recreated and would have to be patched.

This leaves us with two options:
-Serialize only the expression text and re-parse on deserialization. This is what the .NET Regex class does and this is how saving expressions works now. The serialized data is small but the expression has to be re-parsed on load.
-Serialize the whole AST. This would take up more space but would not require re-parsing. This is more work to implement.

I've already implemented serialization support in expressions and in my experience parsing is not slow. Try serializing all of your expressions and let me know if it is very slow.
Aug 21, 2007 at 4:46 PM

OK, thanks for you comments.


a.- Flee support Date datatype without predefined operators (only definition variable). ?
b.- Flee support Date literals , by example: #25/12/2005# ?


anyDate = DateSerial(1971, 1, 9)

days = DateDiff(DateInterval.Day, Now, anyDate)

Aug 21, 2007 at 8:46 PM
>a.- Flee support Date datatype without predefined operators (only definition variable). ?
Are you saying that you don't want the overloaded operators on the Date type? The only ones defined are addition, subtraction, and comparison. You don't have to use them; you can create your own custom functions that manipulate or create datetimes.

>b.- Flee support Date literals , by example: #25/12/2005# ?
This is tricky because how the date is interpreted depends on the current culture. I got into trouble trying to implement a culture-sensitive decimal point so I'm wary of doing this.