question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unclear SetExpression with parameter behavior

See original GitHub issue

Hi,

var interpreter = new Interpreter();
var parameter = new Parameter("x", typeof(int));
var expression = interpreter.Parse("x + 1", parameter).Expression;

var lambda = interpreter
    .SetExpression("value", expression)
    .Parse("value + 1", parameter);

var result = lambda.Invoke(1);

This will throw

System.InvalidOperationException: variable 'x' of type 'System.Int32' referenced from scope '', but it is not defined

Trying to register identifier like below leads to same exception

var lambda = interpreter
    .SetExpression("value", expression)
    .SetIdentifier(new Identifier("x", parameter.Expression)) 
    .Parse("value + 1", parameter);

And only if I mention the identifier in primary expression interpreter.Parse("x + value + 1", parameter) will parse with success.

Could you please advise how to propagate x parameter to internal expression without mentioning it in primary one?

Thanks

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
metoulecommented, Dec 19, 2021

My bad, the parameter simply needs to be the same reference:

var interpreter = new ExpressionInterpreter();
var parameter = Expression.Parameter(typeof(int), "x");
var expression = interpreter.Parse("x + 1", parameter).Expression;

var lambda = interpreter
	.SetExpression("value", expression)
	.Parse("value + 1", parameter);

var result = lambda.Compile().DynamicInvoke(1);
Assert.AreEqual(3, result);
1reaction
metoulecommented, Dec 13, 2021

I like the proposal, but I think we should be careful so that the public interface remains as close as possible to the existing one so that users just have to recompile, but not have to update their code because it’s always painful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SSRS: Passing/Setting parameter to Dataset using ...
1 Answer. here is no way one can pass parameter within expression. You will need to create a subreport to do this. You...
Read more >
Advanced Expressions as Variables
I have been transferring all the expressions that the company uses over to variables that are saved in Excel. Simple ones like this...
Read more >
Parameter Declaration and Attributes
The Uncertainty attribute specifies a relationship between the uncertain parameter at hand, and one or more other (uncertain) parameters in your model. The ......
Read more >
Column Elements and Expressions — SQLAlchemy 2.0 ...
Produce an column-expression-level unary DISTINCT clause. ... positional argument in order to be valid; a and_() construct with no arguments is ambiguous.
Read more >
hail.expr.functions
Parameters ---------- x Object to capture and broadcast as an expression. ... This matches the behavior of Python's ``range``. Parameters ---------- start ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found