commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitri Blinov (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (JEXL-271) Hoisted variable is lost when currying lambda
Date Mon, 03 Sep 2018 08:13:00 GMT

    [ https://issues.apache.org/jira/browse/JEXL-271?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16601863#comment-16601863
] 

Dmitri Blinov commented on JEXL-271:
------------------------------------

I have found a fix for both of these problems, for the first we need to fix a constructor
of {{Curried}} to honor a {{Closure}} as a valid base,
{code:java}
        protected Curried(Script base, Object[] args) {
            super(base.jexl, base.source, base.script);
            Scope.Frame sf = (base instanceof Curried) ? ((Curried) base).frame : 
                             (base instanceof Closure) ? ((Closure) base).frame :null;
            if (sf != null) {
            ...
        }
{code}
For the second we need to fix {{Scope.getSymbol()}} method to fetch symbol from parent with
hoist option set to true
{code:java}
    private Integer getSymbol(String name, boolean hoist) {
        Integer register = namedVariables != null ? namedVariables.get(name) : null;
        if (register == null && hoist && parent != null) {
            Integer pr = parent.getSymbol(name, true);
            ...
    }
{code}
If there are no objections, can I have the changes to be applied the source tree?

> Hoisted variable is lost when currying lambda
> ---------------------------------------------
>
>                 Key: JEXL-271
>                 URL: https://issues.apache.org/jira/browse/JEXL-271
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 3.1
>            Reporter: Dmitri Blinov
>            Priority: Major
>
> I have noticed that when I curry the lambda that contains hoisted variable, then binding
to that variable is lost when I call curried lambda. The following test case illustrates the
problem
> {code}
>     @Test
>     public void testCurry4() throws Exception {
>         JexlEngine jexl = new JexlBuilder().strict(false).create();
>         JexlScript base = jexl.createScript("var base = 2; var sum = (x, y, z)->{
base + x + y + z }; var y = sum.curry(1); y(2,3)");
>         Object result = base.execute(null);
>         Assert.assertEquals(8, result);
>     }
> {code}
> To put it another way, the following script returns {{2}} when it should return {{0}};
> {code}var base = 2; var sum = (x, y, z)->{ base + x + y + z }; var y = sum.curry(1);
sum(1, 2, 3) - y(2,3){code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message