[
https://issues.apache.org/jira/browse/JEXL-200?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15341534#comment-15341534
]
Henri Biestro commented on JEXL-200:
------------------------------------
I'm afraid hoisted variables do not behave as you describe; variables captured
by a function body are not references but copies stored in the local function
stack frame (like arguments).
{code}
@Test
public void test200b() throws Exception {
JexlContext jc = new MapContext();
JexlEngine jexl = new JexlBuilder().create();
JexlScript e = jexl.createScript("var x = 0; var f = (y)->{ x = y; };
f(42); x");
Object r = e.execute(jc);
Assert.assertEquals(0, r);
}
}
{code}
> Support for dynamic scripting in jexl scripts
> ---------------------------------------------
>
> Key: JEXL-200
> URL: https://issues.apache.org/jira/browse/JEXL-200
> Project: Commons JEXL
> Issue Type: New Feature
> Affects Versions: 3.0
> Reporter: Dmitri Blinov
> Assignee: Henri Biestro
> Priority: Minor
>
> Allow for dynamically defined functions inside a script where the definition
> of the function comes from a string expression, for example:
> {code}
> var x = function(y) => "return y+2";
> {code}
> the defined function should be accessible after its definition is
> successfully parsed as ordinary function, and can be evaluated in the current
> context.
> {code}
> if (x(40) eq 42) {...
> {code}
> I think the idea of dynamic script evaluation is not unusual, and though to
> some extent can be implemented via side-added functions like *eval(expr)* a
> dedicated syntax for this will benefit from the simplicity of ordinal
> functions and the ability to control mapping of the arguments between a
> caller and the defined function.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)