commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Biestro (JIRA)" <>
Subject [jira] [Commented] (JEXL-200) Support for dynamic scripting in jexl scripts
Date Tue, 21 Jun 2016 10:39:57 GMT


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).
    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);

> Support for dynamic scripting in jexl scripts
> ---------------------------------------------
>                 Key: JEXL-200
>                 URL:
>             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

View raw message