Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameters are not passed to lambda expression #200

Closed
waclaw66 opened this issue Dec 8, 2021 · 1 comment · Fixed by #201
Closed

Parameters are not passed to lambda expression #200

waclaw66 opened this issue Dec 8, 2021 · 1 comment · Fixed by #201
Assignees
Labels

Comments

@waclaw66
Copy link

waclaw66 commented Dec 8, 2021

Following example returns... Unknown identifier 'x' (at index 5).

var target = new Interpreter(InterpreterOptions.Default | InterpreterOptions.LambdaExpressions);
var listInt = target.Eval<List<int>>("list.Select(n => n > x)", new Parameter("list", new[] { 1, 2, 3 }), new Parameter("x", 1));
Assert.AreEqual(new[] { 2, 3 }, listInt);
@metoule
Copy link
Contributor

metoule commented Dec 8, 2021

I fixed the issue, but a limitation remains: when there's a nested lambda, it's not possible to access the initial lambda parameter. For example, you can't write this:

var target = new Interpreter(InterpreterOptions.Default | InterpreterOptions.LambdaExpressions);
var list = new List<string> { "ab", "cdc" };
target.SetVariable("myList", list);

// the str parameter can't be used in the nested lambda
var results = target.Eval("myList.Select(str => str.Select(c => str.Length))");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants