nreco / lambdaparser

Runtime parser for string expressions (formulas, method calls). Builds dynamic LINQ expression tree and compiles it to lambda delegate.
http://www.nrecosite.com/
MIT License
309 stars 55 forks source link

Allow recursivity #30

Closed EricB85 closed 4 years ago

EricB85 commented 4 years ago

I just discovred your library and its awesome. I am just wondering if it would be possible to do this kind of operations : NOT(NOT(true)) or NOT(1==1) I tried it and obtained this exception : System.InvalidOperationException: 'An expression of type 'System.Boolean' cannot be used to initialize an array of type 'System.Object''

The idea behind those simple exemples is to allow the possibility to chain operations.

Regards,

Eric

VitaliyMF commented 4 years ago

How "NOT" is defined in the evaluation context? You should be able to call a delegate multiple times.

Standard built-in boolean negation is "!" operator.

EricB85 commented 4 years ago

Sorry you are right, I did a lot of experiments and misinterpreted an error. My message is valable for this type of syntax : NOT(1==1) I played with your unit tests so the NOT is varContext["NOT"] = (Func<bool, bool>)((t) => !t);

VitaliyMF commented 4 years ago

NOT(NOT(true)) works as expected, however something is definitely wrong when argument of a function is a result of comparison.

Let me check what is wrong here.

VitaliyMF commented 4 years ago

Bugfix is shipped in 1.0.12

EricB85 commented 4 years ago

It's now perfect :) Thank you.