Parsing Lambda expression pre-evalutes it with given arguments
See original GitHub issueWhen Parsing lambda expression, it evaluates the predicate and cannot be reused (e.g. from cache) with another parameter value. See an example that demonstrates it.
var target = new Interpreter(InterpreterOptions.Default | InterpreterOptions.LambdaExpressions);
var list = new Parameter("list", new[] { 1, 2, 3 });
var value1 = new Parameter("value", 1);
var value2 = new Parameter("value", 2);
var expression = "list.Where(x => x > value)";
var lambda = target.Parse(expression, list, value1);
var result = lambda.Invoke(list, value2);
Assert.AreEqual(new[] { 3 }, result);
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Is there an easy way to parse a (lambda expression) string ...
There is no general way to parse a string into a lambda expression without a full compilation, because lambda expressions can reference ...
Read more >Lambda expressions and anonymous functions
To create a lambda expression, you specify input parameters (if any) on the left side of the lambda operator and an expression or...
Read more >Make Your Own Language 6: Parsing Lambda Functions
This is the sixth episode of a series where you build your first programming language, using these videos as a guide.
Read more >C# Lambda Expressions Simplified | Syntax & Practical ...
The lambda operator =>, which may be read as “goes to” or “becomes,” is used in all lambda expressions. The Input Parameters are...
Read more >How to Use Python Lambda Functions
Arguments. Like a normal function object defined with def , Python lambda expressions support all the different ways of passing arguments. This includes:....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have an idea that might work, but I’m not yet sure it will. The idea is to create a dictionary of all the captured variables, and access it when needed:
Proof of concept of such a body’s creation:
I have a working prototype, that also fixes the limitation I highlighted in #200. It still needs some work, but I might wait until your PR is merged because it impacts the
Lambda
class.